2011-03-21 113 views
1

我有兩個簡單的國防部重寫規則mod_rewrite的規則問題

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

的第一個作品,但第二dosent。我認爲第一個覆蓋第二,但我不知道如何解決它

回答

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

試一下。

+0

都能跟得上。沒有工作形式我 – prista 2011-03-21 13:47:05

+0

經過仔細觀察,這是你的正則表達式是錯誤的,而不是mod_rewrite本身。你的第一個正則表達式將匹配你希望在第二個正則表達式中捕獲的內容,因爲你的(。*)匹配了所有內容 - 並且匹配「details /」。我可以爲您提供合適的,但您可能希望在從別人處獲得解決方案之前嘗試自行修復您的正則表達式。 – Furicane 2011-03-21 14:26:13

+0

我改變了規則的順序,它似乎工作正常。 – prista 2011-03-21 14:42:34

0

嘗試

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

你可以嘗試一些事情。其中之一是重新排序的規則:

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

另一個辦法是改變圖案,使得正斜槓不匹配的俱樂部名稱,像這樣:

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