SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    http://www.mydomain.com/section/subS...ID=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.

  2. #2
    SitePoint Enthusiast dyer85's Avatar
    Join Date
    Nov 2004
    Location
    L2 cache.
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ISTM, the Apache Configuration forum would be the best place to ask.
    "Structure padding is the use of extraneous materials to
    enhance the shape of a struct and make it more attractive
    to members of the opposite struct. (see also 'struct
    silicone.')" -- Eric Sosman

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dyer85 View Post
    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 Learn Apache mod_rewrite: 13 Real-world Examples
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,645
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    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
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, nvm. Think I got it all figured out.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •