.htaccess - htaccess 两个参数 mod-rewrite 问题

标签 .htaccess mod-rewrite url-rewriting seo

我正在尝试设置一个更友好的 URL 系统,但不幸地失败了。我希望能够像这样传递 1 或 2 个 GET 参数:

http://website.com/1234/123456

其中 1234 是第一个参数,123456 是第二个参数。

在我的尝试中,Apache 始终将 /1234/ 视为文件夹 参数。到目前为止,这是我尝试过的:

RewriteRule ^([^/]*)/([^/]*)$ index.php?id=$1&pa=$2 [L]

RewriteRule ^(.*)/(.*)$ index.php?id=$1&pa=$2
RewriteRule ^(.*)$      index.php?id=$1 [L]

最佳答案

你可以这样做:

RewriteEngine On
RewriteRule ^/?index\.php$ - [L]
RewriteRule ^/?(?:([^/]*)(?:/([^/]*)/?)?)?$ /index.php?id=$1&pa=$2 [L]

它有点严格和困惑,所以你可以试试:

RewriteEngine On
RewriteRule ^/?index\.php$ - [L]
RewriteRule ^/?(([^/]*)(/?(.*)))?$ /index.php?id=$2&pa=$4 [L]

这将使一切都过去,所以 host.com/123/1233/56 将重写为 host.com/index.php?id=123&pa=1233/56 而第一个不会重写它,因为 56

关于.htaccess - htaccess 两个参数 mod-rewrite 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10358229/

相关文章:

git - 使用 git repo 处理 .htaccess 的最佳方法是什么?

.htaccess 不让 robots.txt 通过

apache - 在 raspbian 的 apache2 上强制使用 SSL 和 WWW

apache - 重定向错误 : Wordpress + Let's Encrypt (Certbot) + SSL only + non-www

regex - htaccess 将所有图像重定向到不同的位置并将图像名称放入新的 url

.htaccess - mod_rewrite &/+结果 :+chosen+nickname+%22preorrinkap%22

CakePHP 和 SSL

url-rewriting - Yii网址重写

.htaccess - 从 URL 请求中删除 .php 文件扩展名

apache - 使用 htaccess 进行子域重定向而不更改地址栏中的 URL