0

我有这个网址

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 的正确代码是什么 谢谢

4

1 回答 1

0

这是因为 URI/sahara/product-action-viewsubcat-catparent-40.html也匹配第一个模式:product-action-(.*)\.html$(.*)正则表达式中匹配所有内容viewsubcat-catparent-40部分与您的 URI 部分匹配。

您要么需要使表达式更具限制性,要么更改两个规则的顺序:

更具限制性(类似这样):

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
于 2013-05-03T04:32:53.110 回答