2011-03-20 32 views
0

我想整理我的網站上的網址。我寫了以下規則。對於Apache重寫問題:相似的網址格式

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] 

也可以工作,但打破了第一條規則。有沒有人有任何解決方案的想法。

感謝,

回答

1

是的,你需要爲了使重寫規則的條件,而不是適用於任何您正則表達式匹配添加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] 
+0

謝謝你的答案:) – joepour 2011-03-21 01:24:46