Remove query strings from 301 redirects

I am trying to create the appropriate 301 redirects for a site that was originally built using query strings. The old URL structure is as follows:

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 in the new domain. The new domain URL is as follows:

 http://www.newsite.com/info 

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

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

It only redirects fine, but it retains the original URL string, so the new URL in the browser looks like this:

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

I definitely miss the Apache / 301 expert, and I know how to fix it. I just want to take everything off myself? on the.

Really appreciate any help.

+6
source share
2 answers

two options:

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

or

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

the question mark at the end seems critical. The second one looks a little cleaner (first leaves a question mark at the end of your URL)

+28
source

Try adding this code to the .htaccess that is specified for oldsite.com :

 RewriteCond %{REQUEST_URI} ^/about/index.cfm$ RewriteRule ^(.+) http://www.newsite.com/info/ [R=301,QSA] 

Following actions?

0
source

Source: https://habr.com/ru/post/916388/


All Articles