Simple regex problem - please help.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeddiki
    Contributor
    • Jan 2009
    • 290

    Simple regex problem - please help.

    Hi ,

    My simple redirect is working EXCEPT if there is a period in the string.

    This is what I have:


    Code:
    RewriteCond %{HTTP_HOST} ^([^.]+).example.net [NC]
    RewriteCond %{HTTP_HOST} !^www.example.net [NC]
    
    RewriteRule ^.*$ http://example.net/disp_page.php?a=%1 [NC,QSA,L]
    So this works fine with :

    potatoes.exampl e.net

    that goes to example.net/disp_page.php?a =potatoes

    and the page displays

    BUT if I have

    recipes.potatoe s.example.net

    then it doesn't work

    It should go to : example.net/disp_page.php?a =recipes.potato es

    Which would work fine.

    Does any one know how I should adjust my code above so that it takes everything up to the ".example.n et"?

    Thanks.
  • helimeef
    New Member
    • Sep 2007
    • 77

    #2
    Code:
    RewriteCond %{HTTP_HOST} ^(.+)\.example\.net [NC]
    Backslash your periods. They're special characters in regexes -- the reason that your code actually happens to work is because the period selects anything. This would have even matched www4exampleanet .
    This new regex just selects everything before the string ".example.n et"

    Comment

    Working...