简体   繁体   中英

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

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

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

RewriteEngine on
RewriteRule ^index.php / [L,R=301]

Try the modified RewriteCond below

RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php(\?[^\ ]*)?\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM