Remove query strings from 301 redirect

混江龙づ霸主 提交于 2019-12-18 13:22:45

问题


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.


回答1:


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)




回答2:


Try to add this code into the .htaccess that specified for oldsite.com:

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

Follow up?



来源:https://stackoverflow.com/questions/10708301/remove-query-strings-from-301-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!