I'm attempting to set up Apache such that various error pages display with headers/footers appropriate to the context of the error. If the user was requesting a corporate page, I want to show the error with the corporate look and feel. If the error occurs in our application, I want to show it with the application look. Unfortunately, Apache does not want to play along.
In my testing, I've setup Apache to use a particular document when displaying an HTTP 503
error:
# Service Unavailable
ErrorDocument 503 /errors/error_503.shtml
In that document, using SSI directives and environment variables, I have constructed some if/else logic, which could conditionally include this or that header based on the content of an environment variable. This is is my test file:
<!--#if expr="${is_corporate}" -->
corporate here.
<!--#else -->
I'M NOT CORPORATE.
<!--#endif -->
<!--#echo var="is_corporate" -->
<!--#echo var="REQUEST_URI" -->
This is a 503 error message! Check it out!
However, I can't seem to match the request URI using SetEnvIf
in the apache config, for no reason that I can understand.
<Location />
# Allow error documents to use the application or corporate header as appropriate
SetEnvIfNoCase Request_URI /corporate/home/ is_corporate # this does not match
SetEnvIfNoCase Request_URI ^/$ is_corporate # this does not match
SetEnvIfNoCase Request_URI ^/c is_corporate # this does not match
SetEnvIfNoCase Request_URI ^/C is_corporate # this does not match
SetEnvIfNoCase Request_URI .*/ is_corporate # this matches
SetEnvIfNoCase Request_URI .* is_corporate # this matches
</Location>
In this particular case, my error document, printing the contents of REQUEST_URI
displays: /Corporate/Home/
, and always indicates that is_corporate
is empty. Using SetEnvIfNoCase
should make this a case insensitive match, but trying uppercase/lowercase doesn't seem to make a difference.
Since the SetEnvIf
regex is supposed to be pcre compatible, I tested the regex in perl, just to make sure my regex was legit, and should work the way I intend:
vezult@zapazoid:~$ echo '/Corporate/Home' |perl -e 'while(<>) { if (/^\/c/i) { print("match!!: $_\n");} else { print("no match: $_\n"); }}'
match!!: /Corporate/Home
It does. Anyway, so I'm stumped. What might I be missing that is preventing my SetEnvIf
statement to behaving as I expect?