Apache Redirect 301 fails when using GET parameters, such as ?blah=

Martijn Heemels picture Martijn Heemels · Aug 11, 2009 · Viewed 29.6k times · Source

I've built a new PHP site for a customer and want to redirect the top ranking Google results from the old site structure to the new one.

I've put several dozen Redirect 301's in a .htaccess in the documentroot, and while some work fine I'm having issues with a bunch of others.

This works fine:

Redirect 301 /nl/flash/banner_new.swf http://www.example.com/actueel/nieuws.html?action=show&f_id=152

This doesn't work! (leading to a 404 since the redirect is simply skipped):

Redirect 301 /nl/index.php?mID=24511&subID=0 http://www.example.com/solutions/printsolutions.html
Redirect 301 /nl/index.php?mID=24512&subID=0 http://www.example.com/support/koppeling-met-omgeving.html

The redirects are mixed in the .htaccess file, and only the redirects with GET parameters appear to fail.

Is there a workaround? Ignoring the failing redirects is not an option to the customer. Thanks for your thoughts.

Answer

Martijn Heemels picture Martijn Heemels · Aug 12, 2009

While Gumbo's answer's reasoning was correct, I could not get his RewriteRule to work.

Adding another RewriteCond did it. The following was tested and works fine.

RewriteCond %{REQUEST_URI} /nl/index.php$
RewriteCond %{QUERY_STRING} ^mID=24511&subID=0$
RewriteRule ^.*$ http://www.example.com/solutions/printsolutions.html [L,R=301]