RewriteRule升级一级

时间:2016-07-11 17:37:09

标签: .htaccess mod-rewrite

我有以下示例网址

http://myWeb.com/for-sale/whateverCategory/item-title/55

我需要这个来解决:

http://myWeb.com/pages/for-sale.html?name=test-title&item_id=55

这就是我尝试但失败的原因:

RewriteRule ^for-sale/([^/.]*)/?$ /pages/for-sale.html?name=$1&item_id=$2 [L,QSA]

如果我将/pages/级别添加到其工作的URL中,例如

http://myWeb.com/pages/for-sale/childCat/item-title/55

但我希望它没有/pages/

我出错的任何想法?

1 个答案:

答案 0 :(得分:1)

您的规则未在正则表达式中正确捕获值$1$2

您可以使用:

RewriteRule ^for-sale/[^/]+/([\w-]+)/([\w-]+)/?$ /pages/for-sale.html?name=$1&item_id=$2 [L,QSA,NC]