.htaccess使用多个正则表达式重写并获取值赋值
当重写规则中没有正则表达式时,设置GET变量没有问题。例如,当我执行.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
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