htaccess rewrite URL to append Google campaign tracking causing redirect loop

拈花ヽ惹草 提交于 2019-12-11 07:16:25

问题


We are attempting to track offline campaigns to using aliased URLs that point to our main site. We need to append Google analytics campaign tracking code to the end of the URL when the domain is one of the aliased domains.

The following redirect appends the correct information but causes a redirect loop, which I would assume because the RewriteCond still matches as true after the RewriteRule is applied.

RewriteCond %{HTTP_HOST} ^bikerhelp911\.com$
RewriteRule (.*) http://bikerhelp911.com/?utm_source=bikerhelp911.com&utm_medium=radio&utm_campaign=Radio%2BCampaign$1 [R=302,L]

I feel like I'm probably doing this the wrong way or making it more complicated than it needs to be.


回答1:


Change your code to this:

RewriteCond %{QUERY_STRING} !utm_campaign= [NC]
RewriteCond %{HTTP_HOST} ^bikerhelp911\.com$
RewriteRule ^(.*)$ /?utm_source=bikerhelp911.com&utm_medium=radio&utm_campaign=Radio%2BCampaign$1 [R=302,L,QSA]


来源:https://stackoverflow.com/questions/10756785/htaccess-rewrite-url-to-append-google-campaign-tracking-causing-redirect-loop

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