htaccess - removes index.php, but not index.php when index.php?z=abc

风格不统一 提交于 2019-12-13 03:21:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!