问题
http:// domain.com/index.php -> http:// domain.com/ - OK
http:// domain.com/index.php?z=abc -> http:// domain.com/index.php?z=abc - not OK, stays the same. This works using the code below:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
How to modify this code so that
http:// domain.com/index.php?z=abc -> http:// domain.com/?z=abc
回答1:
Apache will take care of the query string automatically. All you need is this:
RewriteEngine on
RewriteRule ^index.php / [L,R=301]
回答2:
Try the modified RewriteCond below
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
来源:https://stackoverflow.com/questions/8750822/htaccess-removes-index-php-but-not-index-php-when-index-phpz-abc