Forum Moderators: phranque

Message Too Old, No Replies

Redirect URL with parameters using htaccess

         

ChocolateLover

12:25 pm on Sep 3, 2009 (gmt 0)

10+ Year Member



I'd like to redirect index.php to the root, but pass the parameters too.

This is what I have
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]

This redirects www.example.com/index.php to www.example.com.

I want to be able redirect www.example.com/index.php?id=1 to www.example.com/?id=1

The query string could be anything.

Any help would be appreciated, thanks.

jdMorgan

12:37 pm on Sep 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your rule passes query strings by default, but your RewriteCond is excluding index requests with query strings from being redirected. So add a sub-pattern to it that will accept a query (blank or otherwise) after the URL:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.ph[b]p(\?[^\ ]*)?\[/b] HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]

Note that the query string is never present in the URL-path variable examined by the RewriteRule. Therefore the additional sub-pattern must not be added there.

Jim

ChocolateLover

12:40 pm on Sep 3, 2009 (gmt 0)

10+ Year Member



Thanks so much for your help.