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.
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.
Redirect
does only operate on the URL paths:So the URL query (the part after the first
?
up to the first#
after) is not checked.But you can use mod_rewrite to do that:
Agreeing with both Gumbo's and Martijn's answers ... but:
Typo in Martijn's, there should be be "^" to start the regular expression for the REQUEST_URI condition:
I too could only get Martijn's, not Gumbo's, to work where my .htaccess file was.
Also, if you don't want the parameter string to be passed on with the rewrite, you should add a "?" on the end of the URL:
Otherwise, following Martijn's code, it reads "if your URL is /nl/index.php?mID=24511&subID=0 then redirect to http://www.example.com/solutions/printsolutions.html?mID=24511&subID=0 with a 301 Permanent redirect header and don't process more rules on this URL"
This may or may not be what you want, and to be fair as a general rule if parameters are not understood they will simply be ignored without doing any harm, so it probably won't matter. However if you're wanting to redirect a human to a new page and want "pretty URLs" then stripping off the parameter string is preferable, so stick the "?" on the end of the destination URL.