5

How can I match a query string using LocationMatch with apache?

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

... won't work unfortunately.

watain
  • 4,838
  • 4
  • 34
  • 35
  • 1
    LocationMatch requires a regular Expression, so you will have to at least escape the `/` and `?`. What pattern do you want to match? – Pekka Jan 07 '10 at 10:43

2 Answers2

7

Looks like you can't include query strings in Location/LocationMatch.

From the Apache Docs:

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.

amiuhle
  • 2,673
  • 1
  • 19
  • 28
4

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 :

<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".

ziGuy
  • 41
  • 5