我有这样的网址结构
localhost/sumar/gallery.php?gen=slug-here
我想要清理例如:localhost/sumar/gallery/slug-here
因此我需要针对此情况重写规则,并阻止任何人通过自动将其重定向到http://localhost/sumar/gallery.php?gen=slug-here
来直接点击基本网址localhost/sumar/gallery/slug-here
到目前为止,我尝试过这种方法:
//that works
RewriteRule ^Gallery/([A-Za-z0-9-_]+)/?$ gallery.php?gen=$1
//below one does not seems to work
RewriteCond %{THE_REQUEST} ^GET\ /sumar/gallery\.php\?gen=([\w-]+) [NC]
RewriteRule ^sumar/gallery\.php$ /sumar/Gallery/%1? [R=301,L]
答案 0 :(得分:1)
您需要对原始请求采取行动:
RewriteEngine On
RewriteRule ^(sumar)/Gallery/([\w-]+)/?$ /$1/gallery.php?gen=$1
RewriteCond %{THE_REQUEST} ^GET\ /sumar/gallery\.php\?gen=([\w-]+) [NC]
RewriteRule ^sumar/gallery\.php$ /sumar/Gallery/%1? [R=301,L]
PS:字符集[A-Za-z0-9_]
可以用\w
表示。