我是.htaccess的新手,所以这似乎是一个显而易见的问题 我有以下重写规则
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+Category\.php\?Category=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ Category.php?Category=$1 [L,QSA]
我想在类似的产品页面中添加类似的规则:
RewriteCond %{THE_REQUEST} \s/+product\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ product.php?id=$1 [L,QSA]
然而,当这两个文件位于.htaccess文件中时,它不起作用只有第一个规则才有效,第二个规则会产生错误。 谢谢你看
答案 0 :(得分:0)
进一步详细说明,你可以通过这种方式制定规则:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+Category\.php\?Category=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L]
RewriteCond %{THE_REQUEST} \s/+product\.php\?id=([^\s&]+) [NC]
RewriteRule ^ %1/p/? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/p/?$ product.php?id=$1 [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ Category.php?Category=$1 [L,QSA]