Remove query strings from 301 redirect

Ash picture Ash · May 22, 2012 · Viewed 23.2k times · Source

I am struggling to create appropriate 301 redirects for a site that was originally built using query strings. The old URL structure looks like this:

http://www.oldsite.com/about/index.cfm?fuseaction=cor_av&artID=5049

I want to redirect the entire subfolder (named 'about') to a new page on the new domain. The new domain's URL looks like this:

http://www.newsite.com/info

So, I set up a redirect that looks like this:

redirectMatch 301 ^/about/ http://www.newsite.com/info  

It is redirecting just fine, but it's keeping the original URL string attached, so the new URL ends up looking like this in a browser:

http://www.newsite.com/info/?fuseaction=cor_av&artID=5049 

I'm definitely not enough of an Apache/301 expert ot know how to fix this. I just want to strip off everything from the ? on.

Really appreciate any help.

Answer

kaptinkaos picture kaptinkaos · May 22, 2012

two options:

redirectMatch 301 ^/about/ http://www.newsite.com/info? 

or:

RewriteEngine on
RewriteRule ^about/(.*) http://www.newsite.com/info? [L,R=301]

question mark at the end seems to be the critical bit. Second one looks a little cleaner (first leaves a question mark at the end of your URL)