2013-05-03 64 views
0

我有這個網址的.htaccess爲相同的URL

http://localhost/sahara/product.php?action=viewcat 
http://localhost/sahara/product.php?action=viewsubcat&catparent=40 

和htaccess的是

RewriteRule product-action-(.*)\.html$ product.php?action=$1 
RewriteRule product-action-(.*)-catparent-(.*)\.html$ product.php?action=$1&catparent=$2 

然後當我打電話重寫URL,只有第一個代碼是工作

http://localhost/sahara/product-action-viewcat.html ---> it's work 
http://localhost/sahara/product-action-viewsubcat-catparent-40.html ---> it's not work 

什麼是我的腳本htaccess的正確代碼 謝謝

回答

0

這是因爲URI /sahara/product-action-viewsubcat-catparent-40.html也匹配第一個模式:product-action-(.*)\.html$。正則表達式的(.*)部分匹配的所有內容與您的URI的viewsubcat-catparent-40部分匹配。

您也需要使表達更嚴格,或更改兩個規則的順序:

更嚴格的(像這樣):

RewriteRule product-action-([a-z]+)\.html$ product.php?action=$1 [L] 
RewriteRule product-action-([a-z]+)-catparent-([0-9]+)\.html$ product.php?action=$1&catparent=$2 [L] 

或者只是順序顛倒:

RewriteRule product-action-(.*)-catparent-(.*)\.html$ product.php?action=$1&catparent=$2 
RewriteRule product-action-(.*)\.html$ product.php?action=$1 
+0

好吧,這是工作。謝謝 – 2013-05-03 08:11:44