Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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
.htaccess使用多个正则表达式重写并获取值赋值_.htaccess_Mod Rewrite_Get - Fatal编程技术网

.htaccess使用多个正则表达式重写并获取值赋值

.htaccess使用多个正则表达式重写并获取值赋值,.htaccess,mod-rewrite,get,.htaccess,Mod Rewrite,Get,当重写规则中没有正则表达式时,设置GET变量没有问题。例如,当我执行sample.html?test=OK时,sample.php中的test变量被设置为OK,下面的代码工作正常 RewriteRule ^sample.html sample.php [NC] 当重写规则中存在正则表达式时,问题就开始了。例如,以下内容与上述内容不同 RewriteRule ^sample-(.*).html sample.php?one=$1 [NC] 我想执行URL,比如sample-123.html?t

当重写规则中没有正则表达式时,设置GET变量没有问题。例如,当我执行
sample.html?test=OK
时,
sample.php
中的
test
变量被设置为
OK
,下面的代码工作正常

RewriteRule ^sample.html sample.php [NC]
当重写规则中存在正则表达式时,问题就开始了。例如,以下内容与上述内容不同

RewriteRule ^sample-(.*).html sample.php?one=$1 [NC]
我想执行URL,比如
sample-123.html?test=OK
,而我有
one
test
sample.php
中获取它们的值

我在这里读过多个问题,但没有人回答过这类问题。我看到不同的答案建议使用
RewriteCond
。我试过了,但运气不好,因为我根本不擅长.htaccess


非常感谢。

您需要
QSA
标志:

RewriteRule ^sample-(.+)\.html$ sample.php?one=$1 [L,QSA,NC]
  • QSA
    (查询字符串附加)标志在添加新查询参数时保留现有查询参数
这可能会有帮助: