Tough regex mod_rewrite. Need help

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:

www.mydomain.com/section/subSection/file.tmpl?adTracking=4231CSD2&SID=432&foo=bar

And have it rewrite it to

Classes/Tracker/tracker.php?adTracking=4231CSD2&SID=432&Forward=www.mydomain.com/section/subSection/file.tmpl&foo=bar

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.

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

cst,

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.

Regards,

DK

dklynn:

The long URL minus the www. is:
mydomain.com/section/subSection/file.tmpl?adTracking=4231CSD2&SID=432&foo=bar

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.