mod_setenvif.xml revision 353b33c8469f4e66be201a7f1a111dddcec8482b
0N/A<?xml version="1.0"?>
2362N/A<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
0N/A<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
0N/A<!-- $LastChangedRevision$ -->
0N/A
0N/A<!--
2362N/A Copyright 2002-2005 The Apache Software Foundation or its licensors, as
0N/A applicable.
2362N/A
0N/A Licensed under the Apache License, Version 2.0 (the "License");
0N/A you may not use this file except in compliance with the License.
0N/A You may obtain a copy of the License at
0N/A
0N/A http://www.apache.org/licenses/LICENSE-2.0
0N/A
0N/A Unless required by applicable law or agreed to in writing, software
0N/A distributed under the License is distributed on an "AS IS" BASIS,
0N/A WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0N/A See the License for the specific language governing permissions and
0N/A limitations under the License.
2362N/A-->
2362N/A
2362N/A<modulesynopsis metafile="mod_setenvif.xml.meta">
0N/A
0N/A<name>mod_setenvif</name>
0N/A<description>Allows the setting of environment variables based
0N/Aon characteristics of the request</description>
0N/A<status>Base</status>
0N/A<sourcefile>mod_setenvif.c</sourcefile>
0N/A<identifier>setenvif_module</identifier>
0N/A
0N/A
0N/A<summary>
0N/A
0N/A <p>The <module>mod_setenvif</module> 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
300N/A to make decisions about actions to be taken.</p>
300N/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<example>
0N/A BrowserMatch ^Mozilla netscape<br />
0N/A BrowserMatch MSIE !netscape<br />
0N/A</example>
0N/A</summary>
0N/A
0N/A<seealso><a href="/env.html">Environment Variables in Apache</a></seealso>
0N/A
0N/A<directivesynopsis>
0N/A<name>BrowserMatch</name>
0N/A<description>Sets environment variables conditional on HTTP User-Agent
0N/A</description>
0N/A<syntax>BrowserMatch <em>regex [!]env-variable</em>[=<em>value</em>]
0N/A[[!]<em>env-variable</em>[=<em>value</em>]] ...</syntax>
0N/A<contextlist><context>server config</context>
0N/A<context>virtual host</context><context>directory</context>
0N/A<context>.htaccess</context></contextlist>
0N/A<override>FileInfo</override>
0N/A
0N/A<usage>
0N/A <p>The <directive>BrowserMatch</directive> is a special cases of the
0N/A <directive module="mod_setenvif">SetEnvIf</directive> 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<example>
0N/A BrowserMatchNoCase Robot is_a_robot<br />
0N/A SetEnvIfNoCase User-Agent Robot is_a_robot<br />
0N/A</example>
0N/A
0N/A <p>Some additional examples:</p>
0N/A<example>
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</example>
0N/A</usage>
0N/A</directivesynopsis>
0N/A
0N/A<directivesynopsis>
0N/A<name>BrowserMatchNoCase</name>
0N/A<description>Sets environment variables conditional on User-Agent without
0N/Arespect to case</description>
0N/A<syntax>BrowserMatchNoCase <em>regex [!]env-variable</em>[=<em>value</em>]
0N/A [[!]<em>env-variable</em>[=<em>value</em>]] ...</syntax>
0N/A<contextlist><context>server config</context>
0N/A<context>virtual host</context><context>directory</context>
0N/A<context>.htaccess</context></contextlist>
0N/A<override>FileInfo</override>
0N/A<compatibility>Apache 1.2 and
0N/A above (in Apache 1.2 this directive was found in the
0N/A now-obsolete mod_browser module)</compatibility>
0N/A
0N/A<usage>
0N/A
0N/A <p>The <directive>BrowserMatchNoCase</directive> directive is
0N/A semantically identical to the <directive
0N/A module="mod_setenvif">BrowserMatch</directive> directive.
0N/A However, it provides for case-insensitive matching. For
0N/A example:</p>
0N/A<example>
0N/A BrowserMatchNoCase mac platform=macintosh<br />
0N/A BrowserMatchNoCase win platform=windows<br />
0N/A</example>
0N/A
0N/A <p>The <directive>BrowserMatch</directive> and
0N/A <directive>BrowserMatchNoCase</directive> directives are special cases of
0N/A the <directive module="mod_setenvif">SetEnvIf</directive> and <directive
0N/A module="mod_setenvif">SetEnvIfNoCase</directive>
0N/A directives. The following two lines have the same effect:</p>
0N/A<example>
0N/A BrowserMatchNoCase Robot is_a_robot<br />
0N/A SetEnvIfNoCase User-Agent Robot is_a_robot<br />
0N/A</example>
0N/A</usage>
0N/A</directivesynopsis>
0N/A
0N/A<directivesynopsis>
0N/A<name>SetEnvIf</name>
0N/A<description>Sets environment variables based on attributes of the request
0N/A</description>
0N/A<syntax>SetEnvIf <em>attribute
0N/A regex [!]env-variable</em>[=<em>value</em>]
0N/A [[!]<em>env-variable</em>[=<em>value</em>]] ...</syntax>
0N/A<contextlist><context>server config</context>
0N/A<context>virtual host</context><context>directory</context>
0N/A<context>.htaccess</context></contextlist>
0N/A<override>FileInfo</override>
0N/A
0N/A<usage>
0N/A <p>The <directive>SetEnvIf</directive> 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 four
0N/A things:</p>
0N/A
0N/A<ol>
0N/A<li>An HTTP request header field (see <a
0N/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>Server_Addr</code> - the IP address of the server
0N/A on which the request was received (only with versions later
0N/A than 2.0.43)</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<directive>SetEnvIf</directive> 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
0N/A<li>
0N/A A reference to an extension of an SSL client certificate, located by
0N/A its object id <em>oid</em>.
0N/A If a non-SSL request, or in absense of the configured <em>oid</em>,
0N/A no variable will be set. If the <em>oid</em> is found multiple times,
0N/A the individual strings will be concatenated, separated by a comma <code>','</code>.
0N/A The <em>oid</em> should reference a string-valued extension.
0N/A</li>
0N/A</ol>
0N/A
0N/A<p>The second argument (<em>regex</em>) is a <a
0N/Ahref="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>. Since version 2.0.51 Apache will
0N/A recognize occurrences of <code>$1</code>..<code>$9</code> within
<var>value</var> and replace them by parenthesized subexpressions
of <var>regex</var>.</p>
<example>
<title>Example:</title>
SetEnvIf Request_URI "\.gif$" object_is_image=gif<br />
SetEnvIf Request_URI "\.jpg$" object_is_image=jpg<br />
SetEnvIf Request_URI "\.xbm$" object_is_image=xbm<br />
:<br />
SetEnvIf Referer www\.mydomain\.com intra_site_referral<br />
:<br />
SetEnvIf object_is_image xbm XBIT_PROCESSING=1<br />
:<br />
SetEnvIf OID("2.16.840.1.113730.1.13") "(.*)" NetscapeComment=$1<br />
:<br />
SetEnvIf ^TS* ^[a-z].* HAVE_TS<br />
</example>
<p>The first three will set the environment variable
<code>object_is_image</code> if the request was for an image
file, and the fourth sets <code>intra_site_referral</code> if
the referring page was somewhere on the
<code>www.mydomain.com</code> Web site.</p>
<p>The sixth example will set the <code>NetscapeComment</code>
environment variable to the string found in the corresponding
SSL client certificate field (if found).</p>
<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>
</usage>
<seealso><a href="/env.html">Environment Variables in Apache</a>,
for additional examples.
</seealso>
</directivesynopsis>
<directivesynopsis>
<name>SetEnvIfNoCase</name>
<description>Sets environment variables based on attributes of the request
without respect to case</description>
<syntax>SetEnvIfNoCase <em>attribute regex
[!]env-variable</em>[=<em>value</em>]
[[!]<em>env-variable</em>[=<em>value</em>]] ...</syntax>
<contextlist><context>server config</context>
<context>virtual host</context><context>directory</context>
<context>.htaccess</context></contextlist>
<override>FileInfo</override>
<compatibility>Apache 1.3 and above</compatibility>
<usage>
<p>The <directive>SetEnvIfNoCase</directive> is semantically identical to
the <directive module="mod_setenvif">SetEnvIf</directive> directive,
and differs only in that the regular expression matching is
performed in a case-insensitive manner. For example:</p>
<example>
SetEnvIfNoCase Host Apache\.Org site=apache
</example>
<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>
</usage>
</directivesynopsis>
</modulesynopsis>