Joan
Joan

Reputation: 482

301 redirects: match querystring, don't append it to new redirect

I've set up a number of 301 redirects in an .htaccess file, but I'm having problems with a query string that makes the redirect not match.

Example:

Redirect 301 /about/history/?lang=fr http://www.newdomain.com/fr/history
Redirect 301 /about/history/ http://www.newdomain.com/nl/history

So olddomain.com/about/history/?lang=fr now matches the second rule and redirects to http://www.newdomain.com/nl/history?lang=fr.

I want it to take the ?lang=fr literally and not append the querystring to the new redirect.

How do I do that?

Upvotes: 2

Views: 950

Answers (1)

Olaf Dietsche
Olaf Dietsche

Reputation: 74028

Redirect takes an URL-path, which doesn't include the query string. So, the first Redirect never matches.

To achieve what you want, you can try some sort of content negotiation or use mod_rewrite

RewriteEngine on
RewriteCond %{QUERY_STRING} lang=fr
RewriteRule /about/history/ http://www.newdomain.com/fr/history? [R,L]
RewriteRule /about/history/ http://www.newdomain.com/nl/history [R,L]

When everything works as you expect, you can change R to R=301.

Upvotes: 2

Related Questions