开发者

strip utm_source from url by htaccess then redirect to origin url

I have issues with URLs of website. I have check the server and referrers, then see a lot of strange URLs with some addition var added to original. That may effect the SEO and server load to create those pages.

eg: Original:

xaluan.com/modules.php?name=News&file=article&sid=123456

xaluan.com/modules.php?name=News&file=article&sid=123987

Someone access my web page by url

xaluan.com/modules.php?name=News&file=article&sid=123456&utm_source开发者_StackOverflow=twitterfeed&utm_medium=twitter

xaluan.com/modules.php?name=News&file=article&sid=123987&utm_source=twitterfeed&utm_medium=twitter

I need one .htaccess that can redirect all 301 URLs which have utm_source=twitterfeed&utm_medium=twitter to original one.


You could try this:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^((.*?)&|)utm_
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1?%2 [R=301,NE,L]

It will drop everything from the Querystring after the first utm_.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜