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.
ISTM, the Apache Configuration forum would be the best place to ask.
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.
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?
Ok, nvm. Think I got it all figured out.