2016-08-21 38 views
1

我上面的htaccess的規則:htaccess的,沒有變量去allcategories.php

RewriteRule ^category/([\w-]+)/(\d+)/?$ category.php?categoria=$1&id=$2 [L,QSA,NC] 
RewriteRule ^category/([\w-]+)/?$ category.php?categoria=$1&id=1 [L,QSA,NC] 
RewriteRule ^category/ allcategories.php 

所以,如果我有category/some_namecategory/some_name/id它會重定向到category.php。

如果我只有category/ allcategories.php。

問題是網址是這樣的:

category/j.j._name 
category/victoria%27s_secret 

它有一個值(J.J ...),它被重定向到allcategories.php而不是category.php。哪裏不對?它是特殊字符嗎?怎麼解決?

回答

1

您需要調整您的正則表達式允許的特殊字符:

RewriteRule ^category/([^/]+)/(\d+)/?$ category.php?categoria=$1&id=$2 [L,QSA,NC] 
RewriteRule ^category/([^/]+)/?$ category.php?categoria=$1&id=1 [L,QSA,NC] 
RewriteRule ^category/?$ allcategories.php [L,NC] 

[^/]將匹配除外/什麼。