问题
I have a set of rules that rewrite URL depending on the affiliate. Everything works fine However, I'm having a problem preserving the complete query string in URL. Here's my rewrite rule
RewriteRule ^/(.*\.html) /adb.pl?code=${affcode:$1}&extra=%{QUERY_STRING} [PT,L]
The query in URL gets stripped after affcode.
URL should look like this:
http://mydomain.com?utm_campaign=TEST-AFF&utm_source=TEST-AFF&utm_medium=TEST-AFF&utm_term=TEST-AFF&utm_content=TEST-AFF-JON
Instead I'm getting this in my browser:
http://mydomain.com?utm_campaign=TEST-AFF
I have already tried using QSA and NE flags. But as long as [PT] is there it refuses to work. Any help would be appreciated.
Thanks!
回答1:
The "problem" you are facing has nothing to do with mod_rewrite
. You have a campaign in Google, right? All these utm_something
are just for that. You have a JS from Google for this campaign, right?
So it works this way:
- JS takes these extra parameters from the query string
- then it redirects the browser to Google Analytics URL sending these parameters
- Google Analytics grabs this request and records the visit on your page coming from campaign
- GA sends HTTP redirect response to browser pointing to original URL stripped from all utm_something
Why? Because if they were not stripped, JS would grab them again and this will lead to endless loop of redirects.
来源:https://stackoverflow.com/questions/23225302/apache-rewrite-to-preserve-query-string