PHP - mod_rewrite干净的网址和查询字符串


PHP - mod_rewrite clean urls and query strings

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www'.(.+)
RewriteCond %{HTTPS}s/%1 ^(on(s)|offs)/(.+)
RewriteRule ^ http%2://%3%{REQUEST_URI}/site1 [L,R=301]
RewriteRule ^/site1/catalogue/('w+)/([0-9]+)$ catalogue.php?category=$1&product_id=$2 [QSA,L]

我在处理一些mod_rewrites时遇到了麻烦。我正在尝试完成 3 件事:

1( 删除万维网。从网址

2( 删除.php扩展

3(拥有涉及$_GET变量(查询字符串?

例如,我想要这个网址:

http://www.domain.com/site1/catalogue.php?category=kitchen&product_id=2

变成了这个:

http://www.domain.com/site1/catalogue/kitchen/2

是的,我的 .htaccess 文件在 site1 文件夹/目录中。输入清理过的网址似乎没有正确重定向我。我得到 404。我假设问题是我对查询字符串的最后一次重写规则。

将最后一个规则更改为:

RewriteRule ^catalogue/('w+)/([0-9]+)$ catalogue.php?category=$1&product_id=$2 [QSA,L]

从正则表达式匹配中删除/site1/。还要在RewriteEngine On之后添加以下内容:

RewriteBase /site1/