Forum Moderators: phranque

Message Too Old, No Replies

simple (?) problem with rewrite

         

manuelsechi

6:23 pm on May 3, 2009 (gmt 0)

10+ Year Member



Hello all

I have this two rules:

RewriteRule ^(.*?)-([^/]+).html$ /page1.php?id=$1
RewriteRule ^(.*?)-([^/]+)/(.*?)-([^/]+).html$ /page2.php?id=$3

the problem is that if I use this url:
www.example.com/22-mycategory.html
or this one
www.example.com/2-mycategory/44-mypage.html

rewrite always use the first rule anc call page1.php.

what can I do to differentiate the two rules without change the url format?
I just tried to invert the rules order without no results...

thank you
best regards
Manuel

g1smd

7:13 pm on May 3, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You need to use a pattern that is much less ambiguous and much less greedy than
(.*)
which matches "everything" - and then has to back off and retry many many times.

You also need to add the

[L]
flag to both rules.

To avoid "wildcard malicious duplication" issues, you need to pass ALL variables through the rewrite and check their values are correct using your script. Incorrect values, and incorrect combinations must trigger the script to return a proper 404 HTTP status in the HTTP header.

See also: [webmasterworld.com...]