为什么我的SetEnvIfNoCase指令与请求的URI不匹配?

我试图设置Apache,使各种错误页面显示适合错误上下文的页眉/页脚。 如果用户请求公司页面,我想要显示与企业外观和感觉的错误。 如果在我们的应用程序中发生错误,我想用应用程序外观来显示它。 不幸的是,Apache不想玩。

在我的testing中,我设置了Apache在显示HTTP 503错误时使用特定的文档:

 # Service Unavailable ErrorDocument 503 /errors/error_503.shtml 

在那篇文档中,使用SSI指令和环境variables,我构build了一些if / else逻辑,可以根据环境variables的内容有条件地包含这个或那个头文件。 这是我的testing文件:

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

不过,我似乎无法使用Apacheconfiguration中的SetEnvIf来匹配请求URI,因为我无法理解。

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

在这种特殊情况下,我的错误文档(打印REQUEST_URI的内容)显示: /Corporate/Home/ ,并始终指示is_corporate为空。 使用SetEnvIfNoCase应该使这个不区分大小写匹配,但是尝试大写/小写似乎没有区别。

由于SetEnvIf正则expression式应该是pcre兼容的,我testing了Perl中的正则expression式,只是为了确保我的正则expression式是合法的,并应按我打算的方式工作:

 vezult@zapazoid:~$ echo '/Corporate/Home' |perl -e 'while(<>) { if (/^\/c/i) { print("match!!: $_\n");} else { print("no match: $_\n"); }}' match!!: /Corporate/Home 

它确实。 无论如何,所以我很难过。 我可能会错过的是防止我的SetEnvIf语句行为像我期望的那样?

SetEnvIf的Request_URI参数似乎是在错误文档的服务过程中更新的。

一种解决方法是匹配其他具有父path的其他东西,例如Referer头。