cstegner — 2010-03-26T14:44:02-04:00 — #1
I have basic regex and mod_rewrite skills but this one is a bit beyond them. If anyone could help me and give an explanation of what's going on in the regex it would be greatly appreciated.
I need to be able to take a URL like:
And have it rewrite it to
Now it gets tricky because I only want the URL rewritten if it contains the adTracking param. Otherwise I want it just to go to the URL. Also the foo=bar could be any additional param or multiple params maybe.
Really hope one of you has more expereince with rewrites like this than I do.
dyer85 — 2010-03-27T01:53:55-04:00 — #2
ISTM, the Apache Configuration forum would be the best place to ask.
paul_wilkins — 2010-03-27T06:34:27-04:00 — #3
Yep, they're the best place.
The have threads dedicated to this type of question, with [mod_rewrite Resources and another thread dedicated to an article called [url="http://www.sitepoint.com/forums/showthread.php?t=506064"]Learn Apache mod_rewrite: 13 Real-world Examples](http://www.sitepoint.com/forums/showthread.php?t=183864)
dklynn — 2010-03-27T17:02:35-04:00 — #4
It's very difficult to see the long URLs in this forum but, since it looks like you merely want to add Forwward AND foo key/value pairs, your problem becomes rather trivial: Test for the existence of of the adTracking key with a RewriteCond then redirect with your Forward and foo values in the query string. Using the QSA flag will ensure that the original query string is appended, too, so nothing will be lost.
HOWEVER, another problem is that your redirection is back to the original URI so you'll also need to add another RewriteCond statement to NOT match your foo (or Forward) key.
Give it a try and, if you have problems with it, I'll help you correct your code.
cstegner — 2010-04-05T10:46:52-04:00 — #5
The long URL minus the www. is:
Ok so taking this step by step. I have other rewrites going on above and below this rewrite. So how do I set it to test for the condition of the adTracking var and if there is one in the URL to rewrite and if not to ignore and move onto the other rewrites?
cstegner — 2010-04-05T13:36:04-04:00 — #6
Ok, nvm. Think I got it all figured out.