nickko
nickko

Reputation: 376

htaccess redirect 301 keeping id

i would like redirect permanent 301 :

https://www.toto.com/index.php?id=4

to

https://www.toto.com/?id=4

this could be fine ? =>

RewriteRule index.php?id=([0-9]+)$ /?id=$1 [L,NC,R=301]

Thanks !

Upvotes: 0

Views: 46

Answers (1)

anubhava
anubhava

Reputation: 786291

You cannot match Query String i.e. ? and part after that in RewriteRule.

You can use following rule to remove index.php from all paths but keep query string:

RewriteEngine On

RewriteCond %{THE_REQUEST} /index\.php [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ %1 [L,R=301,NE]

Upvotes: 1

Related Questions