htaccess mod_rewrite issue

Discussion in 'Apache' started by metalfred, Feb 5, 2010.

  1. #1
    Maybe there is a mod_rewrite guru in the apache forums...


    How come my second rule works if I comment out the first rule?

    
    #RewriteRule ^show/(.*)/$ /show.php?name=$1
    RewriteRule ^show/(.*)/season/(.*)/$ /show.php?name=$1&season=$2     
    
    Code (markup):
    If I call http://mydomain/show/Example/season/1/ everything works perfect?

    But If I uncomment my first rule and I call http://mydomain/show/Example/season/1/ only the first rule will work..?

    any idea?
     
    metalfred, Feb 5, 2010 IP
  2. reagent

    reagent Active Member

    Messages:
    95
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    68
    #2
    Try to put your second line first and add [L]:
    RewriteRule ^show/(.*)/season/(.*)/$ /show.php?name=$1&season=$2 [L]
    Code (markup):
    Try to read J.Friedl's book on regular expressions.
     
    Last edited: Feb 7, 2010
    reagent, Feb 7, 2010 IP
  3. metalfred

    metalfred Active Member

    Messages:
    232
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    Thank you. Putting the more explicit rule first solved the problem.
     
    metalfred, Feb 7, 2010 IP
  4. n3r0x

    n3r0x Well-Known Member

    Messages:
    257
    Likes Received:
    4
    Best Answers:
    1
    Trophy Points:
    120
    #4
    You could try to use something like this..
    
    RewriteRule ^show/([a-z]+)/$ /show.php?name=$1
    RewriteRule ^show/([a-z]+)/season/([0-9]+)/$ /show.php?name=$1&season=$2
    
    Code (markup):
     
    n3r0x, Feb 14, 2010 IP