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.

1 Answer 1


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#">
  • So I'm trying to see if it even matches anything: which is m#^/(.*)$# ? Even this still goes to the else block... This is why I'd like to do something like echo %{REQUEST_URI} and check that it's not empty...
    – nodel
    Jul 29, 2020 at 23:51
  • @nodel If REQUEST_URI is empty then you've got bigger problems than this regex! Jul 30, 2020 at 0:00
  • I don't understand why it doesn't work, since doesn't .* match even an empty string? How can I echo this header?
    – nodel
    Jul 30, 2020 at 0:01
  • That doesn't match just an empty string, though. It matches a / at the beginning of the string followed by some text. And you can put the string in the access log, but it's already there! Jul 30, 2020 at 0:21
  • Even m#^(.*)$# goes into the else.. Is there an alternative way to do this with ENV instead of If/Else?
    – nodel
    Jul 30, 2020 at 0:36

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.