我有两个url做一些查询,我正在努力以我想要的方式重写。
首先/shop/index.php?category=catslug
我想要的
/shop/category
第二
/shop/index.php?product=slug
/shop/category/product
我有这个当前:
RewriteRule ^shop/([A-Za-z0-9-]+)/?$ shop/index.php?category=$1 [L]
RewriteRule ^shop/[A-Za-z-]+/([A-Za-z0-9-]+)/?$ shop/index.php?product=$1 [NC,L]
问题是其中一条规则破坏了所有以shop开头的东西,所以像shop/cart
这样的东西不起作用。我很困惑。这可能吗?
注意,对于shop/cart
, cart
部分匹配第一个RewriteRule
的[A-Za-z0-9-]+
部分。因此,它被重写为shop/index.php?category=cart
。
RewriteRule
,如
RewriteRule ^shop/(cart|this|that|other|thing) - [L]
RewriteRule ^shop/([A-Za-z0-9-]+)/?$ shop/index.php?category=$1 [L]
RewriteRule ^shop/[A-Za-z-]+/([A-Za-z0-9-]+)/?$ shop/index.php?product=$1 [NC,L]
对于匹配管道分隔字符串之一的请求(如cart
), -
表示不更改请求,[L]
表示最后(不继续下一个规则)。