How to add logging to Apache If/Else?

nodel asked:

No matter what, Apache is always going to the else block. I’ve looked at this one, but this one is using a user-defined environment variable. I’m trying to use an apache header to do some dynamic includes.. I’ve read some mixed things about dynamic includes (it might not be possible?). Basically, I’m trying to do this:

<If "%{REQUEST_URI} =~ m#/^.*my-wanted-string.*">
    Include myconf1.conf
    Include myconf2.conf

Is this possible to do in apache 2.4? I’d like to check the logging of REQUEST_URI to confirm that it’s not empty because nothing matches.

My answer:

Your regex is not terminated. You specified a delimiter # but it never appears at the end of your regex.

Further, it then contains a / followed by a ^, which means the beginning of a string. This can never match because the / precedes it. Of course since you have a greedy match .* following the / and are working with a URL path, the / is superfluous and can itself be omitted. The matches themselves are also superfluous in this particular scenario.

You should add the delimiter to the end of the regex, remove the stray ^ character, and possibly other things. Since you didn’t specify what you were trying to do, it may not be possible to advise further.

Something like this will probably get you closer to where you are going:

 <If "%{REQUEST_URI} =~ m#my-wanted-string#">

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.