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?

pregmatch
  • 303
  • 1
  • 5
  • 14
  • i am not sure that you can execute bash directly from apache, anyway, i found this : http://serverfault.com/questions/149153/how-to-run-linux-bash-script-from-web-browser – Froggiz Sep 01 '15 at 09: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 01 '15 at 09: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 01 '15 at 12:13
  • No need to escape forward slashes there, and the locationmatch only matches against the path component of the URL. – covener Sep 06 '15 at 16:31

2 Answers2

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>
Ivan Voras
  • 186
  • 2
  • 7
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

covener
  • 1,685
  • 9
  • 15