[英]underscore and dash are not recognized in a variable
I have the following rule in my .htaccess 我的.htaccess中有以下规则
RewriteRule ^([\da-z]+)/([\da-z]+)/(\d+)/?$ index.php?office=$1&page=$2&news_id=$3 [L,QSA,NC]
RewriteRule ^([\da-z]+)/([\da-z]+)/?$ index.php?office=$1&page=$2 [L,QSA,NC]
when I have an url like: www.test.com/media/continuous-training it doesn't send the continuous-training to the variable. 当我有一个网址,如:www.test.com/media/continuous-training时,它不会将持续训练发送给该变量。 If I don't use dash or underscore everything is fine.
如果我不使用破折号或下划线,则一切都很好。
I think the problem is in my regex in the rule, but not sure how to fix it. 我认为问题出在规则的正则表达式中,但不确定如何解决。
Thanks! 谢谢!
You need to add the -
and _
to your character class. 您需要在字符类中添加
-
和_
。 Use this: 用这个:
RewriteRule ^([\da-z_-]+)/([\da-z_-]+) ...
You might be better off using [W-]
in you character class that will match [A-Za-z0-9_-]
在与
[A-Za-z0-9_-]
匹配的字符类中使用[W-]
可能会更好
RewriteRule ^([\w-]+)/([\w-]+)/(\d+)/?$ index.php?office=$1&page=$2&news_id=$3 [L,QSA]
RewriteRule ^([\w-]+)/([\w-]+)/?$ index.php?office=$1&page=$2 [L,QSA]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.