Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 -->
<!--#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

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?

share|improve this question
I can't test right now, but I wonder if Request_URI's value changes to /errors/error_503.shtml when serving the error page? – Shane Madden Sep 7 '11 at 21:27
@Shane Madden: That seems to be exactly it. Turn that into an answer, and I'll award you the points. – vezult Sep 8 '11 at 13:41
up vote 1 down vote accepted

SetEnvIf's Request_URI parameter seems to be updated with the path of the error document when it's in the process of serving one.

One workaround would be to match against something else that would have the parent path present, such as the Referer header.

share|improve this answer
Thanks. I'll try using Referrer. – vezult Sep 8 '11 at 14:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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