2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Copyright 2002-2005 The Apache Software Foundation or its licensors, as
10 Licensed under the Apache License, Version 2.0 (the "License");
11 you may not use this file except in compliance with the License.
12 You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="mod_setenvif.xml.meta">
25 <name>mod_setenvif</name>
26 <description>Allows the setting of environment variables based
27 on characteristics of the request</description>
29 <sourcefile>mod_setenvif.c</sourcefile>
30 <identifier>setenvif_module</identifier>
35 <p>The <module>mod_setenvif</module> module allows you to set
36 environment variables according to whether different aspects of
37 the request match regular expressions you specify. These
38 environment variables can be used by other parts of the server
39 to make decisions about actions to be taken.</p>
41 <p>The directives are considered in the order they appear in
42 the configuration files. So more complex sequences can be used,
43 such as this example, which sets <code>netscape</code> if the
44 browser is mozilla but not MSIE.</p>
47 BrowserMatch ^Mozilla netscape<br />
48 BrowserMatch MSIE !netscape<br />
52 <seealso><a href="../env.html">Environment Variables in Apache</a></seealso>
55 <name>BrowserMatch</name>
56 <description>Sets environment variables conditional on HTTP User-Agent
58 <syntax>BrowserMatch <em>regex [!]env-variable</em>[=<em>value</em>]
59 [[!]<em>env-variable</em>[=<em>value</em>]] ...</syntax>
60 <contextlist><context>server config</context>
61 <context>virtual host</context><context>directory</context>
62 <context>.htaccess</context></contextlist>
63 <override>FileInfo</override>
66 <p>The <directive>BrowserMatch</directive> is a special cases of the
67 <directive module="mod_setenvif">SetEnvIf</directive> directive that
68 sets environment variables conditional on the
69 <code>User-Agent</code> HTTP request header. The following two
70 lines have the same effect:</p>
72 BrowserMatchNoCase Robot is_a_robot<br />
73 SetEnvIfNoCase User-Agent Robot is_a_robot<br />
76 <p>Some additional examples:</p>
78 BrowserMatch ^Mozilla forms jpeg=yes browser=netscape<br />
79 BrowserMatch "^Mozilla/[2-3]" tables agif frames javascript<br />
80 BrowserMatch MSIE !javascript<br />
86 <name>BrowserMatchNoCase</name>
87 <description>Sets environment variables conditional on User-Agent without
88 respect to case</description>
89 <syntax>BrowserMatchNoCase <em>regex [!]env-variable</em>[=<em>value</em>]
90 [[!]<em>env-variable</em>[=<em>value</em>]] ...</syntax>
91 <contextlist><context>server config</context>
92 <context>virtual host</context><context>directory</context>
93 <context>.htaccess</context></contextlist>
94 <override>FileInfo</override>
95 <compatibility>Apache 1.2 and
96 above (in Apache 1.2 this directive was found in the
97 now-obsolete mod_browser module)</compatibility>
101 <p>The <directive>BrowserMatchNoCase</directive> directive is
102 semantically identical to the <directive
103 module="mod_setenvif">BrowserMatch</directive> directive.
104 However, it provides for case-insensitive matching. For
107 BrowserMatchNoCase mac platform=macintosh<br />
108 BrowserMatchNoCase win platform=windows<br />
111 <p>The <directive>BrowserMatch</directive> and
112 <directive>BrowserMatchNoCase</directive> directives are special cases of
113 the <directive module="mod_setenvif">SetEnvIf</directive> and <directive
114 module="mod_setenvif">SetEnvIfNoCase</directive>
115 directives. The following two lines have the same effect:</p>
117 BrowserMatchNoCase Robot is_a_robot<br />
118 SetEnvIfNoCase User-Agent Robot is_a_robot<br />
124 <name>SetEnvIf</name>
125 <description>Sets environment variables based on attributes of the request
127 <syntax>SetEnvIf <em>attribute
128 regex [!]env-variable</em>[=<em>value</em>]
129 [[!]<em>env-variable</em>[=<em>value</em>]] ...</syntax>
130 <contextlist><context>server config</context>
131 <context>virtual host</context><context>directory</context>
132 <context>.htaccess</context></contextlist>
133 <override>FileInfo</override>
136 <p>The <directive>SetEnvIf</directive> directive defines
137 environment variables based on attributes of the request. The
138 <em>attribute</em> specified in the first argument can be one of four
142 <li>An HTTP request header field (see <a
143 href="http://www.rfc-editor.org/rfc/rfc2616.txt">RFC2616</a>
144 for more information about these); for example: <code>Host</code>,
145 <code>User-Agent</code>, <code>Referer</code>, and
146 <code>Accept-Language</code>. A regular expression may be
147 used to specify a set of request headers.</li>
149 <li>One of the following aspects of the request:
151 <li><code>Remote_Host</code> - the hostname (if available) of
152 the client making the request</li>
154 <li><code>Remote_Addr</code> - the IP address of the client
155 making the request</li>
157 <li><code>Server_Addr</code> - the IP address of the server
158 on which the request was received (only with versions later
161 <li><code>Request_Method</code> - the name of the method
162 being used (<code>GET</code>, <code>POST</code>, <em>et
165 <li><code>Request_Protocol</code> - the name and version of
166 the protocol with which the request was made (<em>e.g.</em>,
167 "HTTP/0.9", "HTTP/1.1", <em>etc.</em>)</li>
169 <li><code>Request_URI</code> - the resource requested on the HTTP
170 request line -- generally the portion of the URL
171 following the scheme and host portion without the query string</li>
175 <li>The name of an environment variable in the list of those
176 associated with the request. This allows
177 <directive>SetEnvIf</directive> directives to test against the result
178 of prior matches. Only those environment variables defined by earlier
179 <code>SetEnvIf[NoCase]</code> directives are available for testing in
180 this manner. 'Earlier' means that they were defined at a broader scope
181 (such as server-wide) or previously in the current directive's scope.
182 Environment variables will be considered only if there was no match
183 among request characteristics and a regular expression was not
184 used for the <em>attribute</em>.</li>
187 A reference to an extension of an SSL client certificate, located by
188 its object id <em>oid</em>.
189 If a non-SSL request, or in absense of the configured <em>oid</em>,
190 no variable will be set. If the <em>oid</em> is found multiple times,
191 the individual strings will be concatenated, separated by a comma <code>','</code>.
192 The <em>oid</em> should reference a string-valued extension.
196 <p>The second argument (<em>regex</em>) is a <a
197 href="http://www.pcre.org/">Perl compatible regular expression</a>.
198 This is similar to a POSIX.2 egrep-style regular expression.
199 If the <em>regex</em> matches against the <em>attribute</em>,
200 then the remainder of the arguments are evaluated.</p>
202 <p>The rest of the arguments give the names of variables to set, and
203 optionally values to which they should be set. These take the form
207 <li><code><em>varname</em></code>, or</li>
209 <li><code>!<em>varname</em></code>, or</li>
211 <li><code><em>varname</em>=<em>value</em></code></li>
214 <p>In the first form, the value will be set to "1". The second
215 will remove the given variable if already defined, and the
216 third will set the variable to the literal value given by
217 <code><em>value</em></code>. Since version 2.0.51 Apache will
218 recognize occurrences of <code>$1</code>..<code>$9</code> within
219 <var>value</var> and replace them by parenthesized subexpressions
220 of <var>regex</var>.</p>
223 <title>Example:</title>
224 SetEnvIf Request_URI "\.gif$" object_is_image=gif<br />
225 SetEnvIf Request_URI "\.jpg$" object_is_image=jpg<br />
226 SetEnvIf Request_URI "\.xbm$" object_is_image=xbm<br />
228 SetEnvIf Referer www\.mydomain\.com intra_site_referral<br />
230 SetEnvIf object_is_image xbm XBIT_PROCESSING=1<br />
232 SetEnvIf OID("2.16.840.1.113730.1.13") "(.*)" NetscapeComment=$1<br />
234 SetEnvIf ^TS* ^[a-z].* HAVE_TS<br />
237 <p>The first three will set the environment variable
238 <code>object_is_image</code> if the request was for an image
239 file, and the fourth sets <code>intra_site_referral</code> if
240 the referring page was somewhere on the
241 <code>www.mydomain.com</code> Web site.</p>
243 <p>The sixth example will set the <code>NetscapeComment</code>
244 environment variable to the string found in the corresponding
245 SSL client certificate field (if found).</p>
247 <p>The last example will set environment variable
248 <code>HAVE_TS</code> if the request contains any headers that
249 begin with "TS" whose values begins with any character in the
253 <seealso><a href="../env.html">Environment Variables in Apache</a>,
254 for additional examples.
259 <name>SetEnvIfNoCase</name>
260 <description>Sets environment variables based on attributes of the request
261 without respect to case</description>
262 <syntax>SetEnvIfNoCase <em>attribute regex
263 [!]env-variable</em>[=<em>value</em>]
264 [[!]<em>env-variable</em>[=<em>value</em>]] ...</syntax>
265 <contextlist><context>server config</context>
266 <context>virtual host</context><context>directory</context>
267 <context>.htaccess</context></contextlist>
268 <override>FileInfo</override>
269 <compatibility>Apache 1.3 and above</compatibility>
273 <p>The <directive>SetEnvIfNoCase</directive> is semantically identical to
274 the <directive module="mod_setenvif">SetEnvIf</directive> directive,
275 and differs only in that the regular expression matching is
276 performed in a case-insensitive manner. For example:</p>
278 SetEnvIfNoCase Host Apache\.Org site=apache
281 <p>This will cause the <code>site</code> environment variable
282 to be set to "<code>apache</code>" if the HTTP request header
283 field <code>Host:</code> was included and contained
284 <code>Apache.Org</code>, <code>apache.org</code>, or any other