是否有可能重定向URL参数在.htaccess文件片段?
即
测试/的index.php?参数= myvalue的
到
测试/ myvalue的/
解决方案
是的。试试这个:
的RewriteCond%{QUERY_STRING}参数=(。*)
重写规则测试/索引 .PHP测试/%1
据什么是匹配的?在之后的 mod_rewrite的文档,查询字符串(部分?
)中分离到的 QUERY_STRING
变量,然后必须单独从URL的主要部分进行测试。在的RewriteCond
,该参数值由常规的前pression括号内捕获(。*)
,并随后可通过%1
在重写规则
。
Is it possible to redirect url parameters as segments in .htaccess file?
i.e.
test/index.php?parameter=MYVALUE
to
test/MYVALUE/
解决方案
Yes. Try this:
RewriteCond %{QUERY_STRING} parameter=(.*)
RewriteRule test/index.php test/%1
According to "What is matched?" in the mod_rewrite docs, the query string (part after the ?
) is separated out into the QUERY_STRING
variable, which then has to be tested separately from the main part of the URL. In RewriteCond
, the parameter value is captured by the regular expression within the parentheses (.*)
, and is then available as %1
in the RewriteRule
.