Forum Moderators: phranque

Message Too Old, No Replies

Conflicts between two rules

.htaccess

         

omoutop

1:55 pm on Feb 10, 2006 (gmt 0)

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



Hi to all!

Within my .htacces file I have two rules that seem to have a conflict and I dont know why since they look identical but the second one contains an additional folder:

RewriteRule ^reviews/([^-]+)-([^/]+)/([^-]+)-reviews-([^-]+)-(.*)\.htm$ reviews/review2.php?location=$1&maj_cat=$2&location=$3&maj_cat=$4&offset=$5 [NC,L]
RewriteRule ^reviews/([^-]+)-([^/]+)/([^/]+)/([^-]+)-reviews-([^-]+)-(.*)\.htm$ reviews/review3.php?location=$1&maj_cat=$2&min_cat=$3&location=$4&min_cat=$5&offset=$6 [NC,L]

If i change my second rule to .html (which is my last option) the page works perfectly, however since I can not unserstand the mistake I am willing to spend some time to fix it. Can you see something wrong?

Thank you in advance for any reccommendations

jdMorgan

3:10 pm on Feb 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your first (shorter) rule can match, even if an additional subdirectory appears in the request, because the [^-]+ patterns would allow a match on <anything>/<anything> as long as <anything> does not include a hyphen. Either of the bolded patterns below could match a a new/unexpected subdirectory in this way.

You could change the pattern to "[^-/]+" so that it also excludes slashes, and that would fix it, but it might be more efficient to simply put the longer rule first:


RewriteRule ^reviews/([^-]+)-([^/]+)/([^/]+)/([^-]+)-reviews-([^-]+)-(.*)\.htm$ reviews/review3.php?location=$1&maj_cat=$2&min_cat=$3&location=$4&min_cat=$5&offset=$6 [NC,L]
RewriteRule ^reviews/([b][^-]+[/b])-([^/]+)/([b][^-][/b]+)-reviews-([^-]+)-(.*)\.htm$ reviews/review2.php?location=$1&maj_cat=$2&location=$3&maj_cat=$4&offset=$5 [NC,L]

Another thing to consider, is that the (.*) pattern at the end could be made more specific:


RewriteRule ^reviews/([^-]+)-([^/]+)/([^/]+)/([^-]+)-reviews-([^-]+)-[b]([^.]+)[/b]\.htm$ reviews/review3.php?location=$1&maj_cat=$2&min_cat=$3&location=$4&min_cat=$5&offset=$6 [NC,L]
RewriteRule ^reviews/([^-]+)-([^/]+)/([^-]+)-reviews-([^-]+)-[b]([^.]+)[/b]\.htm$ reviews/review2.php?location=$1&maj_cat=$2&location=$3&maj_cat=$4&offset=$5 [NC,L]

Jim

omoutop

3:13 pm on Feb 10, 2006 (gmt 0)

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



Thank you for one more tim jdMorgan, I will try on Monday and report back!

Have a good Weekend all of you!