3

I have location match regex

ScriptAlias /script /var/www/somescript.bash
Action some-handler /script virtual
<LocationMatch "/(?:\w+:)?\/\/[^\/]+([^?#]+)/">
    SetHandler some-handler
</LocationMatch>

Now when test that regex https://regex101.com/r/lO0aV1/1 you can see that location is matched but somescript.bash is never executed.

mod_actions are on by the way.

In error log I do not see anything. In access log I got 404.

How can I check that this regex is working? Is there anyway that I can log that?

4
  • i am not sure that you can execute bash directly from apache, anyway, i found this : serverfault.com/questions/149153/…
    – Froggiz
    Sep 1, 2015 at 9:33
  • @Froggiz sure you can. That is ScriptAlias for you just have to set suexec user/group. But my question was more how can I be sure that regex is working beside obvious that is not at the momment? How to log that or something?
    – pregmatch
    Sep 1, 2015 at 9:36
  • for the log you can try to add in your web configuration "ErrorLog /var/log/apache2/error.log" "LogLevel warn" (or info) "CustomLog /var/log/apache2/access.log combined" "RewriteLogLevel 9" RewriteLog "/var/log/apache2/rewritelog" ... but as you get a 404 error, for me that mean that the page isn't considered as being accessible by the client trought apache(if the reg ex is correct)
    – Froggiz
    Sep 1, 2015 at 12:13
  • No need to escape forward slashes there, and the locationmatch only matches against the path component of the URL.
    – covener
    Sep 6, 2015 at 16:31

2 Answers 2

4

Make a CustomLog, with e.g.:

CustomLog "/var/log/httpd/mylog.log" "%h %l %u %t \"%r\" %>s %b what:%{INDICATOR_VAR}e"

and use SetEnv to set the INDICATOR_VAR:

<LocationMatch ...>
    SetEnv INDICATOR_VAR "OK"
</LocationMatch>
3

The simplest way to check that a LocationMatch works is to put a simple mod_headers directive in it and dump the response headers on a test client. e.g. Header set X-DEBUG foo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.