Apache重写问题:类似的url模式

Apache重写问题:类似的url模式,apache,mod-rewrite,url-rewriting,rewrite,Apache,Mod Rewrite,Url Rewriting,Rewrite,我正在尝试整理我网站上的URL。我写了以下规则。为了 index.php?id=work&pid=work-item RewriteRule (.*)/(.*)/$ /index.php?id=$1&pid=$2 [L] 它的工作原理和外观如下: /work/work-item/ 那么: index.php?id=work&tag=1 RewriteRule (.*)/(.*)/$ /index.php?id=$1&tag=$2 [L] 这同样有效,但违

我正在尝试整理我网站上的URL。我写了以下规则。为了

index.php?id=work&pid=work-item 
RewriteRule (.*)/(.*)/$ /index.php?id=$1&pid=$2 [L]
它的工作原理和外观如下:

 /work/work-item/
那么:

index.php?id=work&tag=1
RewriteRule (.*)/(.*)/$ /index.php?id=$1&tag=$2 [L]
这同样有效,但违反了第一条规则。有没有人对解决方案有什么想法

谢谢


Joe

是的,您需要添加一个
RewriteCond
,以便使重写规则有条件,并且不适用于与正则表达式匹配的任何内容

RewriteCond %{QUERY_STRING} ^pid=...$
RewriteRule (.*)/(.*)/$ /index.php?id=$1&pid=$2 [L]

RewriteCond %{QUERY_STRING} ^tag=...$
RewriteRule (.*)/(.*)/$ /index.php?id=$1&tag=$2 [L]