Second rule not working

I have an .htaccess file that I’m having trouble with. Here’s my 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


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.

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:

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

Cheers, funny enough I just got it to work myself by using something along those lines. Thanks for the reply. Case closed me thinks