I have built a brand new PHP site for any customer and wish to redirect the very best ranking Google is a result of that old site structure towards the brand new one.
I have put several dozen Redirect 301's inside a .htaccess within the documentroot, even though some work fine I am getting difficulties with a lot of others.
This works fine:
Redirect 301 /nl/expensive/banner_new.swf http://world wide web.example.com/actueel/nieuws.html?action=show&f_id=152
This does not work! (resulting in a 404 because the redirect is just missed):
Redirect 301 /nl/index.php?mID=24511&subID= http://world wide web.example.com/solutions/printsolutions.html Redirect 301 /nl/index.php?mID=24512&subID= http://world wide web.example.com/support/koppeling-met-omgeving.html
The redirects are included the .htaccess file, and just the redirects with GET parameters seem to fail.
It is possible to workaround? Disregarding the failing redirects isn't a choice towards the customer. Interesting ideas.
Redirect does only work on the URL pathways:
That old URL-path is really a situation-sensitive (%-decoded) path starting with a slash. […]
Therefore the URL query (the part following the first
? as much as the very first
# after) isn't checked.
But you should use mod_rewrite to achieve that:
RewriteCond % ^mID=24511&subID=$ RewriteRule ^nl/index.php$ http://world wide web.example.com/solutions/printsolutions.html [L,R=301] RewriteCond % ^mID=24512&subID=$ RewriteRule ^nl/index.php$ http://world wide web.example.com/support/koppeling-met-omgeving.html [L,R=301]
While Gumbo's answer's reasoning was correct, I possibly could not get his RewriteRule to operate.
Adding another RewriteCond made it happen. The next was examined and works fine.
RewriteCond % /nl/index.php$ RewriteCond % ^mID=24511&subID=$ RewriteRule ^.*$ http://world wide web.example.com/solutions/printsolutions.html [L,R=301]
Saying yes with both Gumbo's and Martjin's solutions ... but:
Typo in Martjin's, there must be be "^" to begin the standard expression for that REQUEST_URI condition:
RewriteCond % ^/nl/index.php$
I too could only get Martjin's, not Gumbo's, to operate where my .htaccess file was.
Also, if you do not want the parameter string to become handed down using the rewrite, you need to give a "?" around the finish from the URL:
RewriteRule ^.*$ http://world wide web.example.com/solutions/printsolutions.html? [L,R=301]
Otherwise, following Martjin's code, it reads "in case your URL is /nl/index.php?mID=24511&subID= then redirect to http://world wide web.example.com/solutions/printsolutions.html?mID=24511&subID= having a 301 Permanent redirect header and do not process more rules about this URL"
This might be what you would like, and also to be fair typically if parameters aren't understood they'll just be overlooked without having done any harm, therefore it most likely will not matter. If however you are attempting to redirect an individual to an alternative page and wish "pretty Web addresses" then draining from the parameter string is more suitable, so stick the "?" around the finish from the destination URL.