使用查询字符串到详细信息页面,但我想像斜线一样重定向SEO友好URL。我使用下面的代码访问页面网址,例如http://localhost/mysite/product/pid/cat/subcat
。它工作正常,但当我单击此链接“ detail.php?pid = 123&cat = mens&subcat = shirt”时,我必须重定向“ product / pid / cat / subcat”
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^product/(.*)/(.*)/(.*)/?$ detail.php?pid=$1&cat=$2&subcat=$3 [L,NC,QSA]
答案 0 :(得分:0)
您可以在根htaccess中使用这两个规则
RewriteEngine on
RewriteBase /mysite/
RewriteCond %{THE_REQUEST} \s/mysite/detail\.php\?pid=([^&\s]+)&cat=([^&\s]+)&subcat=([^&\s]+)\s [NC]
RewriteRule ^ product/%1/%2/%3? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^product/([^/]+)/([^/]+)/([^/]+)$ detail.php?pid=$1&cat=$2&subcat=$3 [L,NC]