htaccess,没有变量转到 allcategories.php
htaccess, no variable go to allcategories.php
我有上面的 htaccess 规则:
RewriteRule ^category/([\w-]+)/(\d+)/?$ category.php?categoria=&id= [L,QSA,NC]
RewriteRule ^category/([\w-]+)/?$ category.php?categoria=&id=1 [L,QSA,NC]
RewriteRule ^category/ allcategories.php
因此,如果我有 category/some_name
或 category/some_name/id
,它将重定向到 category.php。
如果我只有category/
到allcategories.php.
问题是这样的 url:
category/j.j._name
category/victoria%27s_secret
它有一个值 (j.j...),它正在重定向到 allcategories.php 而不是 category.php。怎么了?是特殊字符吗?如何解决?
您需要调整正则表达式以允许使用特殊字符:
RewriteRule ^category/([^/]+)/(\d+)/?$ category.php?categoria=&id= [L,QSA,NC]
RewriteRule ^category/([^/]+)/?$ category.php?categoria=&id=1 [L,QSA,NC]
RewriteRule ^category/?$ allcategories.php [L,NC]
[^/]
将匹配除 /
.
之外的任何内容
我有上面的 htaccess 规则:
RewriteRule ^category/([\w-]+)/(\d+)/?$ category.php?categoria=&id= [L,QSA,NC]
RewriteRule ^category/([\w-]+)/?$ category.php?categoria=&id=1 [L,QSA,NC]
RewriteRule ^category/ allcategories.php
因此,如果我有 category/some_name
或 category/some_name/id
,它将重定向到 category.php。
如果我只有category/
到allcategories.php.
问题是这样的 url:
category/j.j._name
category/victoria%27s_secret
它有一个值 (j.j...),它正在重定向到 allcategories.php 而不是 category.php。怎么了?是特殊字符吗?如何解决?
您需要调整正则表达式以允许使用特殊字符:
RewriteRule ^category/([^/]+)/(\d+)/?$ category.php?categoria=&id= [L,QSA,NC]
RewriteRule ^category/([^/]+)/?$ category.php?categoria=&id=1 [L,QSA,NC]
RewriteRule ^category/?$ allcategories.php [L,NC]
[^/]
将匹配除 /
.