简单的HTACCESS规则重写不会工作

时间:2012-10-19 08:44:57

标签: php .htaccess

RewriteRule ^shop _new_shopAll.php [NC]
RewriteRule ^shop/new _new_shopNew.php [NC]
RewriteRule ^shop/swarovski _new_shopSwar.php [NC]
RewriteRule ^shop/signature _new_shopSig.php [NC]
RewriteRule ^shop/wedding _new_shopWedding.php [NC]
RewriteRule ^shop/celeb _new_shopCeleb.php [NC]
RewriteRule ^shop/sale _new_shopSale.php [NC]
RewriteRule ^shop/sw3 _new_shopSW3.php [NC]

我似乎没有意识到为什么商店才有效,其他一切都有效?需要加$或$ 1吗?

我想要这个工作

/shop?filter=Black = /_new_shopAll.php?filter=Black
/shop/celeb?filter=Black  = /_new_shopCeleb.php?filter=Black
/shop = /_new_shopAll.php
/shop/celeb = /_new_shopCeleb.php

这些是单独的链接。

1 个答案:

答案 0 :(得分:1)

您的第一条规则RewriteRule ^shop _new_shopAll.php [NC]也会匹配shop/new,并在任何其他重写有机会触及该链接之前替换该链接。之后的所有RewriteRules都会看到_new_shopAll.php

您需要在第一条规则的末尾添加$,如下所示: RewriteRule ^shop/?$ _new_shopAll.php [NC] 这样它就不会与shop/new匹配,其他规则将有机会匹配它。