我有以下文件,它接受3个获取参数:v,p和pp
127.0.0.1/archive/index.php
在我的归档目录中:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^v=(\d+) [NC,OR]
RewriteCond %{QUERY_STRING} &v=(\d+)
RewriteRule ^ /archive/%1/? [L,R=301]
RewriteRule ^(\d+)\/?$ /archive/index\.php?v=$1 [L,QSA]
代码重写 127.0.0.1/archive/2/ - > 127.0.0.1/archive/index.php?v=2
但是当我尝试设置301以将参数重定向到干净的URL时,会产生无限循环。我只需要v参数从 / archive /?v = x或/archive/index.php?v=x
重定向到/ archive / x /答案 0 :(得分:0)
您可以在/archive/.htaccess
中使用此规则:
DirectoryIndex index.php
RewriteEngine On
RewriteBase /archive/
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /index\.php\?v=([0-9]+) [NC]
RewriteRule ^ %1? [R=302,L]
# internal forward from pretty URL to actual one
RewriteRule ^([0-9]+)/?$ index.php?v=$1 [L,QSA]