Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 变量中无法识别下划线和破折号_Php_Regex_Apache_.htaccess_Seo - Fatal编程技术网

Php 变量中无法识别下划线和破折号

Php 变量中无法识别下划线和破折号,php,regex,apache,.htaccess,seo,Php,Regex,Apache,.htaccess,Seo,我的.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] 当我有一个url,比如:www.test.com/media/continuous-traini

我的.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]
当我有一个url,比如:www.test.com/media/continuous-training时,它不会将持续训练发送给变量。如果我不使用破折号或下划线,一切都很好

我想问题出在规则中的正则表达式中,但不确定如何解决它


谢谢

您需要将
-
添加到角色类中。使用以下命令:

RewriteRule ^([\da-z_-]+)/([\da-z_-]+) ...

您最好在字符类中使用与
[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]