Apache rewrite to preserve query string

笑着哭i 提交于 2019-12-13 16:50:25

问题


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

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