4

I am trying to use LocationMatch regex to try to match when a certain file is uploaded or downloaded through an application. The application uses query strings in the URL.

The request:

"POST /uploads.js?attachment_id=2&filename=issues%20(12).csv&content_type=application%2Fvnd.ms-excel HTTP/1.1" 200 336

I am noticing that the Regex doesn't seem to be able to see query string characters that come after the "?" in the URL.
Is that correct? and Why?
Is there a way to be able to Regex match whats in the query string portion?

2 Answers2

10

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

fooquency
  • 143
  • 4
Vivien
  • 116
  • 1
  • 3
0

No, LocationMatch does not match query_string.

To complement the answer you may want to use RewriteCond from mod_rewrite to match whatever query string and then redirect it internally or externally to wherever you want, since you haven't specified the purpose other than matching the query_string, there is hardly anything more to say.

Daniel Ferradal
  • 2,415
  • 1
  • 8
  • 13