htaccess - removes index.php, but not index.php wh

2019-08-29 10:28发布

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

2条回答
一夜七次
2楼-- · 2019-08-29 10:56

Try the modified RewriteCond below

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
查看更多
家丑人穷心不美
3楼-- · 2019-08-29 10:57

Apache will take care of the query string automatically. All you need is this:

RewriteEngine on
RewriteRule ^index.php / [L,R=301]
查看更多
登录 后发表回答