2013-05-03 43 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