mod_rewrite - having a problem when tryin to call different ids

Discussion in 'Apache' started by Chrilz, Apr 10, 2007.

  1. #1
    Im working on this new website, where im using mod_rewrite with great success. It works just fine when im trying to call on id, and also when im trying to call its sub-id. Im using these rules:
    RewriteRule ^/?([0-9A-Za-z]+)$ index.php?id=$1
    RewriteRule ^/?([0-9A-Za-z]+)/([0-9]+)$ index.php?id=$1&idx=$2 [L]

    But im making a script so that i can use pagination on some of my pages. The pagination script works just well, when im using the original url-strings, eg. index.php?id=videos&page=2. But when im trying to use mod_rewrite to make the links look nice(http://homepage.com/videos/2), it doesn't work. It loads the design of the homepage succesfully, but it doesn't change the content to the right, but just stays on the page i loaded in the begining.
    I've used this rule: RewriteRule ^/?([0-9A-Za-z]+)/([0-9]+)$ index.php?id=$1&page=$2.

    So my .htacccess file looks like this:
    RewriteEngine on
    RewriteRule ^/?([0-9A-Za-z]+)$ index.php?id=$1
    RewriteRule ^/?([0-9A-Za-z]+)/([0-9]+)$ index.php?id=$1&page=$2
    RewriteRule ^/?([0-9A-Za-z]+)/([0-9]+)$ index.php?id=$1&idx=$2 [L]

    To get a better idea of what i exactly mean you can look here, http://media.dild.net/videos

    Can any of you smart people out their see what im doing wrong?
     
    Chrilz, Apr 10, 2007 IP
  2. malmklang

    malmklang Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I would assume that the two rules for the two values being identical poses a problem, apache doesn't know which url to rewrite to.
    Try [QSA] also.

    RewriteRule ^/?([0-9A-Za-z]+)$ index.php?id=$1 [QSA, L]
    RewriteRule ^/?([0-9A-Za-z]+)/([0-9]+)$ index.php?id=$1&page=$2 [QSA, L]
    RewriteRule ^/?([0-9A-Za-z]+)/Ident/([0-9]+)$ index.php?id=$1&idx=$2 [QSA, L]
    Code (markup):
    Might need Ident to be first in the rewrite, but try :p
     
    malmklang, Apr 11, 2007 IP
  3. Chrilz

    Chrilz Peon

    Messages:
    110
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Unfortunaly this doesn't work. It just brings a server error called 500 or something like that.
    But, your idea that i was missing an Ident was right. my code now looks like this:
    RewriteEngine on
    RewriteRule ^/?([0-9A-Za-z]+)$ index.php?id=$1
    RewriteRule ^/?([0-9A-Za-z]+)/([0-9]+)$ index.php?id=$1&idx=$2
    RewriteRule ^/?([0-9A-Za-z]+)/page/([0-9]+)$ index.php?id=$1&page=$2 [L]
    And this works!

    Thank you ;).
     
    Chrilz, Apr 11, 2007 IP