【问题标题】:Apache, LocationMatch: match query stringApache,LocationMatch:匹配查询字符串
【发布时间】:2010-01-07 10:35:27
【问题描述】:

如何将使用 LocationMatch 的查询字符串与 apache 匹配?

<LocationMatch "/index.php\?a=b.*">
// ...

...不幸的是,它不会工作。

【问题讨论】:

  • LocationMatch 需要正则表达式,因此您至少必须转义 /?。你想匹配什么模式?

标签: apache query-string locationmatch


【解决方案1】:

您似乎不能在 Location/LocationMatch 中包含查询字符串。

来自Apache Docs

对于所有源(非代理)请求,要匹配的 URL 是 /path/ 形式的 URL 路径。 不得包含方案、主机名、端口或查询字符串。对于代理请求,要匹配的 URL 的格式为 scheme://servername/path,并且必须包含前缀。

【讨论】:

    【解决方案2】:

    https://serverfault.com/questions/848320/can-locationmatch-regex-match-query-string-portion

    实际上,从 Apache 2.4(或更低版本)开始使用如下标签是可能的:

    <LocationMatch "/test/upload.js">
            <If "%{QUERY_STRING} =~ /query=test/">
                    ..
                    'Your directives'
                    ..
           </If>
    </LocationMatch>
    

    在此配置指令仅适用于 URL 格式为“/test/upload.js”并包含查询“query=test”的情况。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 2014-07-21
      • 2016-03-07
      • 2012-12-26
      • 1970-01-01
      相关资源
      最近更新 更多