SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Mar 2009
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Second rule not working

    I have an .htaccess file that I'm having trouble with. Here's my code

    Code:
    RewriteRule ^([0-9]+)/([a-zA-Z0-9_-]+)\.html$ page1.php?&id=$1&lname=$2
    RewriteRule ^([0-9]+)/([a-zA-Z0-9_-]+)\.html$ page2.php?&id=$1&fname=$2
    The first link is correct and works fine and gives: http://www.mysite.com/1/bloggs.html
    However the second does not work and goes to page cannot be found. The link looks like: http://www.mysite.com/1/fred.html

    what I've found is if I switch the id number and the name around like so, it works

    Code:
    RewriteRule ^([0-9]+)/([a-zA-Z0-9_-]+)\.html$ page1.php?&id=$1&lname=$2
    RewriteRule ^([a-zA-Z0-9_-])/([0-9]+)\.html$ page2.php?&fname=$1&id=$2
    Can two rules not be the same even if they don't go to the same page? Does each rule have to be unique or is there something I'm missing? I always find rewriting urls a headache.

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,219
    Mentioned
    153 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by freakystreak View Post
    Can two rules not be the same even if they don't go to the same page? Does each rule have to be unique or is there something I'm missing? I always find rewriting urls a headache.
    Ding! You got it. Your first rule matches both URLs, there isn't anything differentiating them so apache knows where to send each one.

    One solution would be to give it a differentiation
    mysite.com/1/bylastname/bloggs.html
    mysite.com/1/byfirstname/fred.html

    With the corresponding rules:
    Code:
    RewriteRule ^([0-9]+)/bylastname/([a-zA-Z0-9_-]+)\.html$ page1.php?&id=$1&lname=$2
    RewriteRule ^([0-9]+)/byfirstname/([a-zA-Z0-9_-]+)\.html$ page2.php?&id=$1&fname=$2

  3. #3
    SitePoint Addict
    Join Date
    Mar 2009
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers, funny enough I just got it to work myself by using something along those lines. Thanks for the reply. Case closed me thinks


Tags for this Thread

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
  •