htaccess mod_rewrite and php issue

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

  1. #1
    Can anyone please tell me how to fix this....

    Here is my htaccess file:
    
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^show/(.*)/$ /show.php?name=$1 
    RewriteRule ^show/(.*)/season/(.*)/$ /show.php?name=$1&season=$2 
    
    Code (markup):
    var_dump($_GET); returns nothing when calling /show/Testname/

    If I use this one instead:
    
    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^[B]tv[/B]show/(.*)/$ /show.php?name=$1 
    RewriteRule ^[B]tv[/B]show/(.*)/season/(.*)/$ /show.php?name=$1&season=$2 
    
    Code (markup):
    var_dump($_GET); returns

    name=Testname when calling /tvshow/Testname/

    and

    name=Testname
    season=Testname/season/1/ when calling /tvshow/Testname/season/1/

    Please help!
     
    metalfred, Feb 5, 2010 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You could always rename show.php to something else.

    Otherwise, try this (with the [L] at the end):

    RewriteRule ^show/(.*)/$ /show.php?name=$1 [L]
     
    SmallPotatoes, Feb 5, 2010 IP
  3. metalfred

    metalfred Active Member

    Messages:
    232
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #3
    Thanks for your reply, but that didnt help.

    I have changed this Options +FollowSymlinks to this Options +FollowSymlinks -MultiViews

    and this is working:

    RewriteRule ^show/(.*)/$ /show.php?name=$1

    So, calling http://mydomain/show/Example/ works.

    But this still does not work:

    RewriteRule ^show/(.*)/season/(.*)/$ /show.php?name=$1&season=$2

    Variable $_GET['name'] becomes:

    name=Example/season/1/

    when calling http://mydomain/show/Example/season/1/

    wtf..
     
    metalfred, Feb 5, 2010 IP
  4. metalfred

    metalfred Active Member

    Messages:
    232
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    I have found something...

    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):
    Now if I call http://mydomain/show/Example/season/1/ everything works perfect?
     
    metalfred, Feb 5, 2010 IP
  5. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #5
    ^show/(.*)/$ will happily swallow up show/Example/season/1.

    Put the more specific rule first.
     
    SmallPotatoes, Feb 5, 2010 IP