menriquez
menriquez

Reputation: 249

.htaccess rewrite rule matching issue

so i've been tasked to make this URL work

foobar.com/city.homes

and this..

foobar.com/page-2/city.homes

with this rewrite

RewriteRule ^(.*).homes$      search-results.asp?area=$1&proptype=home

so my first try seems, logically enough i think

RewriteRule ^page-(.*)/(.*).homes$     search-results.asp?area=$2&proptype=home&page=$1

however, no matter where i put it in .htaccess, its not working the way i'm expecting it to. it never matches the second rule unless i remove the first one.

Upvotes: 1

Views: 38

Answers (1)

anubhava
anubhava

Reputation: 784918

Your regex are wrong and are overlapping.

Have your rules like this:

RewriteRule ^page-([0-9])/([^.]+)\.homes$ search-results.asp?area=$2&proptype=home&page=$1 [L,QSA]

RewriteRule ^([^.]+)\.homes$ search-results.asp?area=$2&proptype=home [L,QSA]

Upvotes: 1

Related Questions