mod_rewrite rules problem

Tag: apache , mod-rewrite Author: Romic Date: 2011-03-05

I have two simple mod rewrite rules

RewriteRule club/(.*)-(.*).html$ club.php?id=$2&%{QUERY_STRING}
RewriteRule club/details/(.*)-(.*).html$ /club/details.php?id=$2&%{QUERY_STRING}

The first one works, but the second dosent. I think the first override the second but I can`t figure out how to fix it

Other Answer1

RewriteRule club/(.*)-(.*).html$ club.php?id=$2&%{QUERY_STRING} [L]
RewriteRule club/details/(.*)-(.*).html$ /club/details.php?id=$2&%{QUERY_STRING}

Try with that.

comments:

Nope. Doesn't work form me
After taking a closer look, it's your regular expression that's wrong and not mod_rewrite itself. Your first regular expression will match what you wanted to capture in the second one since you have (.*) which matches everything - and it matched "details/" also. I can provide you with the appropriate one, however you might want to try to fix your regexp yourself before getting the solution from someone else.
I changed the order of rules and it`s seems works fine.

Other Answer2

try

RewriteRule club/(.*)-(.*).html$ club.php?id=$2 [L,QSA]
RewriteRule club/details/(.*)-(.*).html$ club/details.php?id=$2 [L,QSA]

Other Answer3

You could try a couple of things. One would be to reorder the rules:

RewriteRule club/details/(.*)-(.*).html$ /club/details.php?id=$2&%{QUERY_STRING}
RewriteRule club/(.*)-(.*).html$ club.php?id=$2&%{QUERY_STRING}

Another would be to change the pattern so that forward slashes don't match the club name, like so:

RewriteRule club/([^/]*)-(.*).html$ club.php?id=$2&%{QUERY_STRING}
RewriteRule club/details/(.*)-(.*).html$ /club/details.php?id=$2&%{QUERY_STRING}