mod_setenvif.xml revision e942c741056732f50da2074b36fe59805d370650
d24d4c5159bcb11c25bb294926cfe7105c789ea9slive<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
e942c741056732f50da2074b36fe59805d370650slive<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
d6736da1df3ed890b1e24c604503dce770e1346cslive<modulesynopsis>
d24d4c5159bcb11c25bb294926cfe7105c789ea9slive<description>Allows the setting of environment variables based
d24d4c5159bcb11c25bb294926cfe7105c789ea9sliveon characteristics of the request</description>
d6736da1df3ed890b1e24c604503dce770e1346cslive<compatibility>Available in Apache 1.3 and later</compatibility>
d6736da1df3ed890b1e24c604503dce770e1346cslive <p>The <module>mod_setenvif</module> module allows you to set
d6736da1df3ed890b1e24c604503dce770e1346cslive environment variables according to whether different aspects of
d6736da1df3ed890b1e24c604503dce770e1346cslive the request match regular expressions you specify. These
d6736da1df3ed890b1e24c604503dce770e1346cslive environment variables can be used by other parts of the server
d6736da1df3ed890b1e24c604503dce770e1346cslive to make decisions about actions to be taken.</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive <p>The directives are considered in the order they appear in
d6736da1df3ed890b1e24c604503dce770e1346cslive the configuration files. So more complex sequences can be used,
d6736da1df3ed890b1e24c604503dce770e1346cslive such as this example, which sets <code>netscape</code> if the
d6736da1df3ed890b1e24c604503dce770e1346cslive browser is mozilla but not MSIE.</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive BrowserMatch ^Mozilla netscape<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive BrowserMatch MSIE !netscape<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive<seealso><a href="/env.html">Environment Variables in Apache</a></seealso>
d6736da1df3ed890b1e24c604503dce770e1346cslive<directivesynopsis>
d6736da1df3ed890b1e24c604503dce770e1346cslive<description>Sets environment variables conditional on HTTP User-Agent
d6736da1df3ed890b1e24c604503dce770e1346cslive</description>
d6736da1df3ed890b1e24c604503dce770e1346cslive<syntax>BrowserMatch <em>regex env-variable</em>[=<em>value</em>]
832292cf428167a83e71c7f17493fc0ab6cb7a7eslive<context>virtual host</context><context>directory</context>
d6736da1df3ed890b1e24c604503dce770e1346cslive<compatibility>Apache 1.2 and
d6736da1df3ed890b1e24c604503dce770e1346cslive above (in Apache 1.2 this directive was found in the
d6736da1df3ed890b1e24c604503dce770e1346cslive now-obsolete mod_browser module)</compatibility>
d6736da1df3ed890b1e24c604503dce770e1346cslive <p>The <directive>BrowserMatch</directive> directive defines
d6736da1df3ed890b1e24c604503dce770e1346cslive environment variables based on the <code>User-Agent</code> HTTP
d6736da1df3ed890b1e24c604503dce770e1346cslive request header field. The first argument should be a POSIX.2
d6736da1df3ed890b1e24c604503dce770e1346cslive extended regular expression (similar to an
d6736da1df3ed890b1e24c604503dce770e1346cslive <code>egrep</code>-style regex). The rest of the arguments give
d6736da1df3ed890b1e24c604503dce770e1346cslive the names of variables to set, and optionally values to which they
d6736da1df3ed890b1e24c604503dce770e1346cslive should be set. These take the form of</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive <p>In the first form, the value will be set to "1". The second
d6736da1df3ed890b1e24c604503dce770e1346cslive will remove the given variable if already defined, and the
d6736da1df3ed890b1e24c604503dce770e1346cslive third will set the variable to the value given by
d6736da1df3ed890b1e24c604503dce770e1346cslive <code><em>value</em></code>. If a <code>User-Agent</code>
d6736da1df3ed890b1e24c604503dce770e1346cslive string matches more than one entry, they will be merged.
d6736da1df3ed890b1e24c604503dce770e1346cslive Entries are processed in the order in which they appear, and
d6736da1df3ed890b1e24c604503dce770e1346cslive later entries can override earlier ones.</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive BrowserMatch ^Mozilla forms jpeg=yes browser=netscape<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive BrowserMatch "^Mozilla/[2-3]" tables agif frames javascript<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive BrowserMatch MSIE !javascript<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive <p>Note that the regular expression string is
d6736da1df3ed890b1e24c604503dce770e1346cslive <strong>case-sensitive</strong>. For case-INsensitive matching,
d6736da1df3ed890b1e24c604503dce770e1346cslive see the <directive
d6736da1df3ed890b1e24c604503dce770e1346cslive directive.</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive <directive>BrowserMatchNoCase</directive> directives are special cases of
d6736da1df3ed890b1e24c604503dce770e1346cslive the <directive module="mod_setenvif">SetEnvIf</directive> and <directive
d6736da1df3ed890b1e24c604503dce770e1346cslive directives. The following two lines have the same effect:</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive BrowserMatchNoCase Robot is_a_robot<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive SetEnvIfNoCase User-Agent Robot is_a_robot<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive</directivesynopsis>
d6736da1df3ed890b1e24c604503dce770e1346cslive<directivesynopsis>
d6736da1df3ed890b1e24c604503dce770e1346cslive<description>Sets environment variables conditional on User-Agent without
d6736da1df3ed890b1e24c604503dce770e1346csliverespect to case</description>
d6736da1df3ed890b1e24c604503dce770e1346cslive<syntax>BrowserMatchNoCase <em>regex env-variable</em>[=<em>value</em>]
832292cf428167a83e71c7f17493fc0ab6cb7a7eslive<context>virtual host</context><context>directory</context>
d6736da1df3ed890b1e24c604503dce770e1346cslive<compatibility>Apache 1.2 and
d6736da1df3ed890b1e24c604503dce770e1346cslive above (in Apache 1.2 this directive was found in the
d6736da1df3ed890b1e24c604503dce770e1346cslive now-obsolete mod_browser module)</compatibility>
d6736da1df3ed890b1e24c604503dce770e1346cslive <p>The <directive>BrowserMatchNoCase</directive> directive is
d6736da1df3ed890b1e24c604503dce770e1346cslive semantically identical to the <directive
d6736da1df3ed890b1e24c604503dce770e1346cslive module="mod_setenvif">BrowserMatch</directive> directive.
d6736da1df3ed890b1e24c604503dce770e1346cslive However, it provides for case-insensitive matching. For
d6736da1df3ed890b1e24c604503dce770e1346cslive example:</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive BrowserMatchNoCase mac platform=macintosh<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive BrowserMatchNoCase win platform=windows<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive <directive>BrowserMatchNoCase</directive> directives are special cases of
d6736da1df3ed890b1e24c604503dce770e1346cslive the <directive module="mod_setenvif">SetEnvIf</directive> and <directive
d6736da1df3ed890b1e24c604503dce770e1346cslive directives. The following two lines have the same effect:</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive BrowserMatchNoCase Robot is_a_robot<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive SetEnvIfNoCase User-Agent Robot is_a_robot<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive</directivesynopsis>
d6736da1df3ed890b1e24c604503dce770e1346cslive<directivesynopsis>
d6736da1df3ed890b1e24c604503dce770e1346cslive<description>Sets environment variables based on attributes of the request
d6736da1df3ed890b1e24c604503dce770e1346cslive</description>
832292cf428167a83e71c7f17493fc0ab6cb7a7eslive<context>virtual host</context><context>directory</context>
d6736da1df3ed890b1e24c604503dce770e1346cslive<compatibility>Apache 1.3 and
d6736da1df3ed890b1e24c604503dce770e1346cslive above; the Request_Protocol keyword and environment-variable
d6736da1df3ed890b1e24c604503dce770e1346cslive matching are only available with 1.3.7 and later</compatibility>
d6736da1df3ed890b1e24c604503dce770e1346cslive <p>The <directive>SetEnvIf</directive> directive defines environment
d6736da1df3ed890b1e24c604503dce770e1346cslive variables based on attributes of the request. These attributes
d6736da1df3ed890b1e24c604503dce770e1346cslive can be the values of various HTTP request header fields (see <a
d6736da1df3ed890b1e24c604503dce770e1346cslive href="http://www.rfc-editor.org/rfc/rfc2616.txt">RFC2616</a>
d6736da1df3ed890b1e24c604503dce770e1346cslive for more information about these), or of other aspects of the
d6736da1df3ed890b1e24c604503dce770e1346cslive request, including the following:</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive <li><code>Remote_Host</code> - the hostname (if available) of
d6736da1df3ed890b1e24c604503dce770e1346cslive the client making the request</li>
d6736da1df3ed890b1e24c604503dce770e1346cslive <li><code>Remote_Addr</code> - the IP address of the client
d6736da1df3ed890b1e24c604503dce770e1346cslive making the request</li>
d6736da1df3ed890b1e24c604503dce770e1346cslive <li><code>Remote_User</code> - the authenticated username (if
d6736da1df3ed890b1e24c604503dce770e1346cslive available)</li>
d6736da1df3ed890b1e24c604503dce770e1346cslive <li><code>Request_Method</code> - the name of the method
d6736da1df3ed890b1e24c604503dce770e1346cslive being used (<code>GET</code>, <code>POST</code>, <em>et
d6736da1df3ed890b1e24c604503dce770e1346cslive <li><code>Request_Protocol</code> - the name and version of
d6736da1df3ed890b1e24c604503dce770e1346cslive the protocol with which the request was made (<em>e.g.</em>,
d6736da1df3ed890b1e24c604503dce770e1346cslive following the scheme and host portion</li>
d6736da1df3ed890b1e24c604503dce770e1346cslive <p>Some of the more commonly used request header field names
d6736da1df3ed890b1e24c604503dce770e1346cslive include <code>Host</code>, <code>User-Agent</code>, and
d6736da1df3ed890b1e24c604503dce770e1346cslive <p>If the <em>attribute</em> name doesn't match any of the
d6736da1df3ed890b1e24c604503dce770e1346cslive special keywords, nor any of the request's header field names,
d6736da1df3ed890b1e24c604503dce770e1346cslive it is tested as the name of an environment variable in the list
d6736da1df3ed890b1e24c604503dce770e1346cslive of those associated with the request. This allows
d6736da1df3ed890b1e24c604503dce770e1346cslive <directive>SetEnvIf</directive> directives to test against the result of
d6736da1df3ed890b1e24c604503dce770e1346cslive prior matches.</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive <strong>Only those environment variables defined by earlier
d6736da1df3ed890b1e24c604503dce770e1346cslive <code>SetEnvIf[NoCase]</code> directives are available for
d6736da1df3ed890b1e24c604503dce770e1346cslive testing in this manner. 'Earlier' means that they were
d6736da1df3ed890b1e24c604503dce770e1346cslive defined at a broader scope (such as server-wide) or
d6736da1df3ed890b1e24c604503dce770e1346cslive previously in the current directive's scope.</strong>
d6736da1df3ed890b1e24c604503dce770e1346cslive <p><em>attribute</em> may be a regular expression when used to
d6736da1df3ed890b1e24c604503dce770e1346cslive match a request header. If <em>attribute</em> is a regular
d6736da1df3ed890b1e24c604503dce770e1346cslive expression and it doesn't match any of the request's header
d6736da1df3ed890b1e24c604503dce770e1346cslive names, then <em>attribute</em> is not tested against the
d6736da1df3ed890b1e24c604503dce770e1346cslive request's environment variable list.</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive SetEnvIf Request_URI "\.gif$" object_is_image=gif<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive SetEnvIf Request_URI "\.jpg$" object_is_image=jpg<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive SetEnvIf Request_URI "\.xbm$" object_is_image=xbm<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive SetEnvIf Referer www\.mydomain\.com intra_site_referral<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive SetEnvIf object_is_image xbm XBIT_PROCESSING=1<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive SetEnvIf ^TS* ^[a-z].* HAVE_TS<br />
d6736da1df3ed890b1e24c604503dce770e1346cslive <p>The first three will set the environment variable
d6736da1df3ed890b1e24c604503dce770e1346cslive <code>object_is_image</code> if the request was for an image
d6736da1df3ed890b1e24c604503dce770e1346cslive file, and the fourth sets <code>intra_site_referral</code> if
d6736da1df3ed890b1e24c604503dce770e1346cslive the referring page was somewhere on the
d6736da1df3ed890b1e24c604503dce770e1346cslive <p>The last example will set environment variable
d6736da1df3ed890b1e24c604503dce770e1346cslive <code>HAVE_TS</code> if the request contains any headers that
d6736da1df3ed890b1e24c604503dce770e1346cslive begin with "TS" whose values begins with any character in the
d6736da1df3ed890b1e24c604503dce770e1346cslive set [a-z].</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive</directivesynopsis>
d6736da1df3ed890b1e24c604503dce770e1346cslive<directivesynopsis>
d6736da1df3ed890b1e24c604503dce770e1346cslive<description>Sets environment variables based on attributes of the request
d6736da1df3ed890b1e24c604503dce770e1346cslivewithout respect to case</description>
d6736da1df3ed890b1e24c604503dce770e1346cslive<syntax>SetEnvIfNoCase <em>attribute regex env-variable</em>[=<em>value</em>]
832292cf428167a83e71c7f17493fc0ab6cb7a7eslive<context>virtual host</context><context>directory</context>
d6736da1df3ed890b1e24c604503dce770e1346cslive <p>The <directive>SetEnvIfNoCase</directive> is semantically identical to
d6736da1df3ed890b1e24c604503dce770e1346cslive the <directive module="mod_setenvif">SetEnvIf</directive> directive,
d6736da1df3ed890b1e24c604503dce770e1346cslive and differs only in that the regular expression matching is
d6736da1df3ed890b1e24c604503dce770e1346cslive performed in a case-insensitive manner. For example:</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive SetEnvIfNoCase Host Apache\.Org site=apache
d6736da1df3ed890b1e24c604503dce770e1346cslive <p>This will cause the <code>site</code> environment variable
d6736da1df3ed890b1e24c604503dce770e1346cslive to be set to "<code>apache</code>" if the HTTP request header
d6736da1df3ed890b1e24c604503dce770e1346cslive <code>Apache.Org</code>, <code>apache.org</code>, or any other
d6736da1df3ed890b1e24c604503dce770e1346cslive combination.</p>
d6736da1df3ed890b1e24c604503dce770e1346cslive</directivesynopsis>
d6736da1df3ed890b1e24c604503dce770e1346cslive</modulesynopsis>