Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...