Help with conflicting mod-rewrite
I want to be able to use foo on both of these mod re-writes this is what I currently have开发者_如何学编程 and is working fine:
#Links to categorys
RewriteRule foo/(.*)/ foo.php?cat=$1
RewriteRule foo/(.*) foo.php?cat=$1
#Links to categorys with pagination
RewriteRule fooo/(.*)/(.*)/ foo.php?cat=$1&id=$2
RewriteRule fooo/(.*)/(.*) foo.php?cat=$1&id=$2
But really want to have this instead:
#Links to categorys
RewriteRule foo/(.*)/ foo.php?cat=$1
RewriteRule foo/(.*) foo.php?cat=$1
#Links to categorys with pagination
RewriteRule foo/(.*)/(.*)/ foo.php?cat=$1&id=$2
RewriteRule foo/(.*)/(.*) foo.php?cat=$1&id=$2
as both are relevent to each other (same pages) just a case of additional pagination id's but if I do not have the extra "o" it conflicts and so give me a 404
any help is much appreciated
The problem comes from the fact that this rule:
RewriteRule foo/(.*)
...will match anything that would match your pagination rules, and will do it first. The simplest solution is to just invert the rule order and make a few small changes:
#Links to categorys with pagination
RewriteRule foo/([^/]*)/([^/]+)/? foo.php?cat=$1&id=$2
#Links to categorys
RewriteRule foo/([^/]*)/? foo.php?cat=$1
Additionally, if your script can handle id
being passed with no value, you can just condense it all into a single rule:
# Links to categories with optional pagination
RewriteRule foo/([^/]*)(?:/([^/]+))?/? foo.php?cat=$1&id=$2
精彩评论