Apache Rewrite Question: Similar url patterns
I am trying to tidy up the urls on my site. I have written the followin开发者_开发技巧g rules. For
index.php?id=work&pid=work-item
RewriteRule (.*)/(.*)/$ /index.php?id=$1&pid=$2 [L]
Which works and looks like this:
/work/work-item/
Then for:
index.php?id=work&tag=1
RewriteRule (.*)/(.*)/$ /index.php?id=$1&tag=$2 [L]
Which also works but breaks the first rule. Does anyone have any ideas for a solution.
Thanks,
Joe
Yes, you need to add a RewriteCond
in order to make the rewrite rule conditional and not apply to anything that matches your regex.
RewriteCond %{QUERY_STRING} ^pid=...$
RewriteRule (.*)/(.*)/$ /index.php?id=$1&pid=$2 [L]
and
RewriteCond %{QUERY_STRING} ^tag=...$
RewriteRule (.*)/(.*)/$ /index.php?id=$1&tag=$2 [L]
精彩评论