Redirect permanent when URL source contains a "?"

193 views Asked by At

I'm looking for some help about a Redirect permanent.

I would like to do a redirect like :

http://www.mydomain.com/site/index.php?code=_fr to http://www.mydomain.com/home

When I try something like that for any URL it's working :

RedirectPermanent /site/index.php URLDEST

But if I want to do that, it doesn't work...

RedirectPermanent /site/index.php?code=_fr URLDEST

I also try something like that :

RewriteRule ^/site/index.php?code=_fr$ URLDEST [R=301]

But it doesn't work either.

How can I achieve this?

1

There are 1 answers

0
arco444 On

You need a condition to check the value of the query string in the rewrite:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^code=_fr$
    RewriteRule ^/site/index.php$ /home [R]

This worked when I tested it, instead of /home, I put in a redirect to google and when I hit /site/index.php?code=_fr that's where it went. Anything else and the rule wasn't matched. Are you sure the page you're redirecting to actually exists? What have you set URLDEST to? If you're getting a 404, either the page your redirecting to is missing or there is some other configuration wrong somewhere. I'd also recommend using Firebug or Charles to look at the response headers of the requests. If you see a 30x then the rule is a match and working.