问题
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