http:// domain.com/index.php - > http:// domain.com/ - 确定
http:// domain.com/index.php?z=abc - > http:// domain.com/index.php?z=abc - 不行,保持不变。 这可以使用以下代码:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
如何修改此代码以便
http:// domain.com/index.php?z=abc -> http:// domain.com/?z=abc
答案 0 :(得分:1)
Apache会自动处理查询字符串。所有你需要的是:
RewriteEngine on
RewriteRule ^index.php / [L,R=301]
答案 1 :(得分:1)
尝试修改下面的RewriteCond
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]