mod_setenvif.html.en revision c22a6dc8ecfb9540649e9d371d0c28676ec6a57d
0N/A<html xmlns="http://www.w3.org/TR/xhtml1/strict"><head><!--
0N/A XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0N/A This file is generated from xml source: DO NOT EDIT
0N/A XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0N/A --><title>mod_setenvif- Apache HTTP Server</title><link href="/style/manual.css" type="text/css" rel="stylesheet"/></head><body><blockquote><div align="center"><img src="/images/sub.gif" alt="[APACHE DOCUMENTATION]"/><h3>Apache HTTP Server Version 2.0</h3></div><h1 align="center">Apache Module mod_setenvif</h1><table cellspacing="1" cellpadding="0" bgcolor="#cccccc"><tr><td><table bgcolor="#ffffff"><tr><td nowrap="nowrap" valign="top"><span class="help">Description:</span></td><td>Allows the setting of environment variables based
0N/Aon characteristics of the request</td></tr><tr><td nowrap="nowrap"><a href="module-dict.html#Status" class="help">Status:</a></td><td>Base</td></tr><tr><td nowrap="nowrap"><a href="module-dict.html#ModuleIdentifier" class="help">Module&nbsp;Identifier:</a></td><td>setenvif_module</td></tr></table></td></tr></table><h2>Summary</h2>
0N/A
0N/A <p>The <code><a href="mod_setenvif.html">mod_setenvif</a></code> module allows you to set
0N/A environment variables according to whether different aspects of
0N/A the request match regular expressions you specify. These
0N/A environment variables can be used by other parts of the server
0N/A to make decisions about actions to be taken.</p>
0N/A
0N/A <p>The directives are considered in the order they appear in
0N/A the configuration files. So more complex sequences can be used,
0N/A such as this example, which sets <code>netscape</code> if the
0N/A browser is mozilla but not MSIE.</p>
0N/A
0N/A<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0N/A BrowserMatch ^Mozilla netscape<br>
0N/A BrowserMatch MSIE !netscape<br>
0N/A</code></td></tr></table></blockquote>
0N/A<h2>Directives</h2><ul><li><a href="#browsermatch">BrowserMatch</a></li><li><a href="#browsermatchnocase">BrowserMatchNoCase</a></li><li><a href="#setenvif">SetEnvIf</a></li><li><a href="#setenvifnocase">SetEnvIfNoCase</a></li></ul><p><strong>See also </strong></p><ul><li><a href="/env.html">Environment Variables in Apache</a></li></ul><hr/><h2><a name="BrowserMatch">BrowserMatch</a> <a name="browsermatch">Directive</a></h2><table cellpadding="1" cellspacing="0" border="0" bgcolor="#cccccc"><tr><td><table bgcolor="#ffffff"><tr><td nowrap="nowrap"><strong>Description: </strong></td><td>Sets environment variables conditional on HTTP User-Agent
0N/A</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Syntax" class="help">Syntax:</a></td><td>BrowserMatch <em>regex [!]env-variable</em>[=<em>value</em>]
0N/A[[!]<em>env-variable</em>[=<em>value</em>]] ...</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Context" class="help">Context:</a></td><td>server config, virtual host, directory, .htaccess</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Override" class="help">Override:</a></td><td>FileInfo</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Status" class="help">Status:</a></td><td>Base</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Module" class="help">Module:</a></td><td>mod_setenvif</td></tr></table></td></tr></table>
0N/A <p>The <code class="directive">BrowserMatch</code> is a special cases of the
0N/A <a href="#setenvif" class="directive"><code class="directive">SetEnvIf</code></a> directive that
0N/A sets environment variables conditional on the
0N/A <code>User-Agent</code> HTTP request header. The following two
0N/A lines have the same effect:</p>
0N/A<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0N/A BrowserMatchNoCase Robot is_a_robot<br>
0N/A SetEnvIfNoCase User-Agent Robot is_a_robot<br>
0N/A</code></td></tr></table></blockquote>
0N/A
0N/A <p>Some additional examples:</p>
0N/A<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0N/A BrowserMatch ^Mozilla forms jpeg=yes browser=netscape<br>
0N/A BrowserMatch "^Mozilla/[2-3]" tables agif frames javascript<br>
0N/A BrowserMatch MSIE !javascript<br>
0N/A</code></td></tr></table></blockquote>
0N/A<hr/><h2><a name="BrowserMatchNoCase">BrowserMatchNoCase</a> <a name="browsermatchnocase">Directive</a></h2><table cellpadding="1" cellspacing="0" border="0" bgcolor="#cccccc"><tr><td><table bgcolor="#ffffff"><tr><td nowrap="nowrap"><strong>Description: </strong></td><td>Sets environment variables conditional on User-Agent without
0N/Arespect to case</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Syntax" class="help">Syntax:</a></td><td>BrowserMatchNoCase <em>regex [!]env-variable</em>[=<em>value</em>]
0N/A [[!]<em>env-variable</em>[=<em>value</em>]] ...</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Context" class="help">Context:</a></td><td>server config, virtual host, directory, .htaccess</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Override" class="help">Override:</a></td><td>FileInfo</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Status" class="help">Status:</a></td><td>Base</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Module" class="help">Module:</a></td><td>mod_setenvif</td></tr><tr><td nowrap="nowrap" align="left" valign="top"><a href="directive-dict.html#Compatibility" class="help">Compatibility:</a></td><td>Apache 1.2 and
0N/A above (in Apache 1.2 this directive was found in the
0N/A now-obsolete mod_browser module)</td></tr></table></td></tr></table>
0N/A
0N/A <p>The <code class="directive">BrowserMatchNoCase</code> directive is
0N/A semantically identical to the <a href="#browsermatch" class="directive"><code class="directive">BrowserMatch</code></a> directive.
0N/A However, it provides for case-insensitive matching. For
0N/A example:</p>
0N/A<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0N/A BrowserMatchNoCase mac platform=macintosh<br>
0N/A BrowserMatchNoCase win platform=windows<br>
0N/A</code></td></tr></table></blockquote>
0N/A
0N/A <p>The <code class="directive">BrowserMatch</code> and
0N/A <code class="directive">BrowserMatchNoCase</code> directives are special cases of
0N/A the <a href="#setenvif" class="directive"><code class="directive">SetEnvIf</code></a> and <a href="#setenvifnocase" class="directive"><code class="directive">SetEnvIfNoCase</code></a>
0N/A directives. The following two lines have the same effect:</p>
0N/A<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0N/A BrowserMatchNoCase Robot is_a_robot<br>
0N/A SetEnvIfNoCase User-Agent Robot is_a_robot<br>
0N/A</code></td></tr></table></blockquote>
0N/A<hr/><h2><a name="SetEnvIf">SetEnvIf</a> <a name="setenvif">Directive</a></h2><table cellpadding="1" cellspacing="0" border="0" bgcolor="#cccccc"><tr><td><table bgcolor="#ffffff"><tr><td nowrap="nowrap"><strong>Description: </strong></td><td>Sets environment variables based on attributes of the request
0N/A</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Syntax" class="help">Syntax:</a></td><td>SetEnvIf <em>attribute
0N/A regex [!]env-variable</em>[=<em>value</em>]
0N/A [[!]<em>env-variable</em>[=<em>value</em>]] ...</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Context" class="help">Context:</a></td><td>server config, virtual host, directory, .htaccess</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Override" class="help">Override:</a></td><td>FileInfo</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Status" class="help">Status:</a></td><td>Base</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Module" class="help">Module:</a></td><td>mod_setenvif</td></tr></table></td></tr></table>
0N/A <p>The <code class="directive">SetEnvIf</code> directive defines
0N/A environment variables based on attributes of the request. The
0N/A <em>attribute</em> specified in the first argument can be one of three
0N/A things:</p>
0N/A
0N/A<ol>
0N/A<li>An HTTP request header field (see <a href="http://www.rfc-editor.org/rfc/rfc2616.txt">RFC2616</a>
0N/A for more information about these); for example: <code>Host</code>,
0N/A <code>User-Agent</code>, <code>Referer</code>, and
0N/A <code>Accept-Language</code>. A regular expression may be
0N/A used to specify a set of request headers.</li>
0N/A
0N/A<li>One of the following aspects of the request:
0N/A <ul>
0N/A <li><code>Remote_Host</code> - the hostname (if available) of
0N/A the client making the request</li>
0N/A
0N/A <li><code>Remote_Addr</code> - the IP address of the client
0N/A making the request</li>
0N/A
0N/A <li><code>Remote_User</code> - the authenticated username (if
0N/A available)</li>
0N/A
0N/A <li><code>Request_Method</code> - the name of the method
0N/A being used (<code>GET</code>, <code>POST</code>, <em>et
0N/A cetera</em>)</li>
0N/A
0N/A <li><code>Request_Protocol</code> - the name and version of
0N/A the protocol with which the request was made (<em>e.g.</em>,
0N/A "HTTP/0.9", "HTTP/1.1", <em>etc.</em>)</li>
0N/A
0N/A <li><code>Request_URI</code> - the resource requested on the HTTP
0N/A request line -- generally the portion of the URL
0N/A following the scheme and host portion without the query string</li>
0N/A </ul>
0N/A</li>
0N/A
0N/A<li>The name of an environment variable in the list of those
0N/Aassociated with the request. This allows
0N/A<code class="directive">SetEnvIf</code> directives to test against the result
0N/Aof prior matches. Only those environment variables defined by earlier
0N/A<code>SetEnvIf[NoCase]</code> directives are available for testing in
0N/Athis manner. 'Earlier' means that they were defined at a broader scope
0N/A(such as server-wide) or previously in the current directive's scope.
0N/AEnvironment variables will be considered only if there was no match
0N/Aamong request characteristics and a regular expression was not
0N/Aused for the <em>attribute</em>.</li>
0N/A</ol>
0N/A
0N/A<p>The second argument (<em>regex</em>) is a <a href="http://www.pcre.org/">Perl compatible regular expression</a>.
0N/AThis is similar to a POSIX.2 egrep-style regular expression.
0N/AIf the <em>regex</em> matches against the <em>attribute</em>,
0N/Athen the remainder of the arguments are evaluated.</p>
0N/A
0N/A<p>The rest of the arguments give the names of variables to set, and
0N/Aoptionally values to which they should be set. These take the form
0N/Aof</p>
0N/A
0N/A <ol>
0N/A <li><code><em>varname</em></code>, or</li>
0N/A
0N/A <li><code>!<em>varname</em></code>, or</li>
0N/A
0N/A <li><code><em>varname</em>=<em>value</em></code></li>
0N/A </ol>
0N/A
0N/A <p>In the first form, the value will be set to "1". The second
0N/A will remove the given variable if already defined, and the
0N/A third will set the variable to the literal value given by
0N/A <code><em>value</em></code>.</p>
0N/A
0N/A<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><p align="center"><strong>Example:</strong></p><code>
0N/A
0N/A SetEnvIf Request_URI "\.gif$" object_is_image=gif<br>
0N/A SetEnvIf Request_URI "\.jpg$" object_is_image=jpg<br>
0N/A SetEnvIf Request_URI "\.xbm$" object_is_image=xbm<br>
0N/A :<br>
0N/A SetEnvIf Referer www\.mydomain\.com intra_site_referral<br>
0N/A :<br>
0N/A SetEnvIf object_is_image xbm XBIT_PROCESSING=1<br>
0N/A :<br>
0N/A SetEnvIf ^TS* ^[a-z].* HAVE_TS<br>
0N/A</code></td></tr></table></blockquote>
0N/A
0N/A <p>The first three will set the environment variable
0N/A <code>object_is_image</code> if the request was for an image
0N/A file, and the fourth sets <code>intra_site_referral</code> if
0N/A the referring page was somewhere on the
0N/A <code>www.mydomain.com</code> Web site.</p>
0N/A
<p>The last example will set environment variable
<code>HAVE_TS</code> if the request contains any headers that
begin with "TS" whose values begins with any character in the
set [a-z].</p>
<p><strong>See also </strong></p><ul><li><a href="/env.html">Environment Variables in Apache</a>,
for additional examples.
</li></ul><hr/><h2><a name="SetEnvIfNoCase">SetEnvIfNoCase</a> <a name="setenvifnocase">Directive</a></h2><table cellpadding="1" cellspacing="0" border="0" bgcolor="#cccccc"><tr><td><table bgcolor="#ffffff"><tr><td nowrap="nowrap"><strong>Description: </strong></td><td>Sets environment variables based on attributes of the request
without respect to case</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Syntax" class="help">Syntax:</a></td><td>SetEnvIfNoCase <em>attribute regex
[!]env-variable</em>[=<em>value</em>]
[[!]<em>env-variable</em>[=<em>value</em>]] ...</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Context" class="help">Context:</a></td><td>server config, virtual host, directory, .htaccess</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Override" class="help">Override:</a></td><td>FileInfo</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Status" class="help">Status:</a></td><td>Base</td></tr><tr><td nowrap="nowrap"><a href="directive-dict.html#Module" class="help">Module:</a></td><td>mod_setenvif</td></tr><tr><td nowrap="nowrap" align="left" valign="top"><a href="directive-dict.html#Compatibility" class="help">Compatibility:</a></td><td>Apache 1.3 and above</td></tr></table></td></tr></table>
<p>The <code class="directive">SetEnvIfNoCase</code> is semantically identical to
the <a href="#setenvif" class="directive"><code class="directive">SetEnvIf</code></a> directive,
and differs only in that the regular expression matching is
performed in a case-insensitive manner. For example:</p>
<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
SetEnvIfNoCase Host Apache\.Org site=apache
</code></td></tr></table></blockquote>
<p>This will cause the <code>site</code> environment variable
to be set to "<code>apache</code>" if the HTTP request header
field <code>Host:</code> was included and contained
<code>Apache.Org</code>, <code>apache.org</code>, or any other
combination.</p>
<hr/></blockquote><h3 align="center">Apache HTTP Server Version 2.0</h3><a href="./"><img src="/images/index.gif" alt="Index"/></a><a href="../"><img src="/images/home.gif" alt="Home"/></a></body></html>