Apache,LocationMatch:匹配查询字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2019594/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Apache, LocationMatch: match query string
提问by watain
How can I match a query string using LocationMatchwith apache?
如何使用LocationMatchapache匹配查询字符串?
<LocationMatch "/index.php\?a=b.*">
// ...
... won't work unfortunately.
......不幸的是不会工作。
回答by amiuhle
Looks like you can't include query strings in Location/LocationMatch.
看起来您不能在Location/ 中包含查询字符串LocationMatch。
From the Apache Docs:
来自Apache 文档:
For all origin (non-proxy) requests, the URL to be matched is a URL-path of the form /path/. No scheme, hostname, port, or query string may be included. For proxy requests, the URL to be matched is of the form scheme://servername/path, and you must include the prefix.
对于所有源(非代理)请求,要匹配的 URL 是 /path/ 形式的 URL-path。不得包含方案、主机名、端口或查询字符串。对于代理请求,要匹配的 URL 格式为 scheme://servername/path,并且必须包含前缀。
回答by ziGuy
https://serverfault.com/questions/848320/can-locationmatch-regex-match-query-string-portion
https://serverfault.com/questions/848320/can-locationmatch-regex-match-query-string-portion
Actually it's possible since Apache 2.4 (or less) using the tag as follow :
实际上这是可能的,因为 Apache 2.4(或更低版本)使用如下标签:
<LocationMatch "/test/upload.js">
<If "%{QUERY_STRING} =~ /query=test/">
..
'Your directives'
..
</If>
</LocationMatch>
In this configuration directives will be applied only in the case the URL is under the form "/test/upload.js" and contains the query "query=test".
在此配置指令中,仅在 URL 为“/test/upload.js”形式并包含查询“query=test”的情况下才应用指令。

