1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org" />
<title>Apache module mod_setenvif</title>
</head>
<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
<body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
vlink="#000080" alink="#FF0000">
<div align="CENTER">
<img src="../images/sub.gif" alt="[APACHE DOCUMENTATION]" />
<h3>Apache HTTP Server Version 1.3</h3>
</div>
<h1 align="CENTER">Module mod_setenvif</h1>
<p>This module provides the ability to set environment
variables based upon attributes of the request.</p>
<p><a href="module-dict.html#Status"
rel="Help"><strong>Status:</strong></a> Base<br />
<a href="module-dict.html#SourceFile"
rel="Help"><strong>Source File:</strong></a>
mod_setenvif.c<br />
<a href="module-dict.html#ModuleIdentifier"
rel="Help"><strong>Module Identifier:</strong></a>
setenvif_module<br />
<a href="module-dict.html#Compatibility"
rel="Help"><strong>Compatibility:</strong></a> Available in
Apache 1.3 and later.</p>
<h2>Summary</h2>
<p>The <samp>mod_setenvif</samp> module allows you to set
environment variables according to whether different aspects of
the request match <a href="../misc/FAQ.html#regex">regular
expressions</a> you specify. These environment variables can be
used by other parts of the server to make decisions about
actions to be taken.</p>
<p>The directives are considered in the order they appear in
the configuration files. So more complex sequences can be used,
such as this example, which sets <code>netscape</code> if the
browser is mozilla but not MSIE.</p>
<blockquote>
<pre>
BrowserMatch ^Mozilla netscape
BrowserMatch MSIE !netscape
</pre>
</blockquote>
<p>For additional information, we provide a document on <a
href="../env.html">Environment Variables in Apache</a>.</p>
<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>
<hr />
<!-- the HR is part of the directive description -->
<h2><a id="browsermatch" name="browsermatch">BrowserMatch
directive</a></h2>
<p><a href="directive-dict.html#Syntax"
rel="Help"><strong>Syntax:</strong></a> BrowserMatch <em>regex
env-variable</em>[=<em>value</em>]
[<em>env-variable</em>[=<em>value</em>]] ...<br />
<a href="directive-dict.html#Default"
rel="Help"><strong>Default:</strong></a> <i>none</i><br />
<a href="directive-dict.html#Context"
rel="Help"><strong>Context:</strong></a> server config, virtual
host, directory, .htaccess<br />
<a href="directive-dict.html#Override"
rel="Help"><strong>Override:</strong></a> FileInfo<br />
<a href="directive-dict.html#Status"
rel="Help"><strong>Status:</strong></a> Base<br />
<a href="directive-dict.html#Module"
rel="Help"><strong>Module:</strong></a> mod_setenvif<br />
<a href="directive-dict.html#Compatibility"
rel="Help"><strong>Compatibility:</strong></a> Apache 1.2 and
above (in Apache 1.2 this directive was found in the
now-obsolete mod_browser module); use in .htaccess files only
supported with 1.3.13 and later</p>
<p>The BrowserMatch directive defines environment variables
based on the <samp>User-Agent</samp> HTTP request header field.
The first argument should be a POSIX.2 extended regular
expression (similar to an <samp>egrep</samp>-style regex). The
rest of the arguments give the names of variables to set, and
optionally values to which they should be set. These take the
form of</p>
<ol>
<li><samp><em>varname</em></samp>, or</li>
<li><samp>!<em>varname</em></samp>, or</li>
<li><samp><em>varname</em>=<em>value</em></samp></li>
</ol>
<p>In the first form, the value will be set to "1". The second
will remove the given variable if already defined, and the
third will set the variable to the value given by
<samp><em>value</em></samp>. If a <samp>User-Agent</samp>
string matches more than one entry, they will be merged.
Entries are processed in the order in which they appear, and
later entries can override earlier ones.</p>
<p>For example:</p>
<pre>
BrowserMatch ^Mozilla forms jpeg=yes browser=netscape
BrowserMatch "^Mozilla/[2-3]" tables agif frames javascript
BrowserMatch MSIE !javascript
</pre>
<p>Note that the regular expression string is
<strong>case-sensitive</strong>. For case-INsensitive matching,
see the <a
href="#browsermatchnocase"><samp>BrowserMatchNoCase</samp></a>
directive.</p>
<p>The <samp>BrowserMatch</samp> and
<samp>BrowserMatchNoCase</samp> directives are special cases of
the <a href="#setenvif"><samp>SetEnvIf</samp></a> and <a
href="#setenvifnocase"><samp>SetEnvIfNoCase</samp></a>
directives. The following two lines have the same effect:</p>
<pre>
BrowserMatchNoCase Robot is_a_robot
SetEnvIfNoCase User-Agent Robot is_a_robot
</pre>
<hr />
<!-- the HR is part of the directive description -->
<h2><a id="browsermatchnocase"
name="browsermatchnocase">BrowserMatchNoCase directive</a></h2>
<p><a href="directive-dict.html#Syntax"
rel="Help"><strong>Syntax:</strong></a> BrowserMatchNoCase
<em>regex env-variable</em>[=<em>value</em>]
[<em>env-variable</em>[=<em>value</em>]] ...<br />
<a href="directive-dict.html#Default"
rel="Help"><strong>Default:</strong></a> <em>none</em><br />
<a href="directive-dict.html#Context"
rel="Help"><strong>Context:</strong></a> server config, virtual
host, directory, .htaccess<br />
<a href="directive-dict.html#Override"
rel="Help"><strong>Override:</strong></a> FileInfo<br />
<a href="directive-dict.html#Status"
rel="Help"><strong>Status:</strong></a> Base<br />
<a href="directive-dict.html#Module"
rel="Help"><strong>Module:</strong></a> mod_setenvif<br />
<a href="directive-dict.html#Compatibility"
rel="Help"><strong>Compatibility:</strong></a> Apache 1.2 and
above (in Apache 1.2 this directive was found in the
now-obsolete mod_browser module)</p>
<p>The <samp>BrowserMatchNoCase</samp> directive is
semantically identical to the <a
href="#BrowserMatch"><samp>BrowserMatch</samp></a> directive.
However, it provides for case-insensitive matching. For
example:</p>
<pre>
BrowserMatchNoCase mac platform=macintosh
BrowserMatchNoCase win platform=windows
</pre>
<p>The <samp>BrowserMatch</samp> and
<samp>BrowserMatchNoCase</samp> directives are special cases of
the <a href="#setenvif"><samp>SetEnvIf</samp></a> and <a
href="#SetEnvIfNoCase"><samp>SetEnvIfNoCase</samp></a>
directives. The following two lines have the same effect:</p>
<pre>
BrowserMatchNoCase Robot is_a_robot
SetEnvIfNoCase User-Agent Robot is_a_robot
</pre>
<hr />
<!-- the HR is part of the directive description -->
<h2><a id="setenvif" name="setenvif">SetEnvIf
directive</a></h2>
<p><a href="directive-dict.html#Syntax"
rel="Help"><strong>Syntax:</strong></a> SetEnvIf <em>attribute
regex env-variable</em>[=<em>value</em>]
[<em>env-variable</em>[=<em>value</em>]] ...<br />
<a href="directive-dict.html#Default"
rel="Help"><strong>Default:</strong></a> <em>none</em><br />
<a href="directive-dict.html#Context"
rel="Help"><strong>Context:</strong></a> server config, virtual
host, directory, .htaccess<br />
<a href="directive-dict.html#Override"
rel="Help"><strong>Override:</strong></a> FileInfo<br />
<a href="directive-dict.html#Status"
rel="Help"><strong>Status:</strong></a> Base<br />
<a href="directive-dict.html#Module"
rel="Help"><strong>Module:</strong></a> mod_setenvif<br />
<a href="directive-dict.html#Compatibility"
rel="Help"><strong>Compatibility:</strong></a> Apache 1.3 and
above; the Request_Protocol keyword and environment-variable
matching are only available with 1.3.7 and later; use in
.htaccess files only supported with 1.3.13 and later</p>
<p>The <samp>SetEnvIf</samp> directive defines environment
variables based on attributes of the request. These attributes
can be the values of various HTTP request header fields (see <a
href="http://www.rfc-editor.org/rfc/rfc2616.txt">RFC2616</a>
for more information about these), or of other aspects of the
request, including the following:</p>
<ul>
<li><samp>Remote_Host</samp> - the hostname (if available) of
the client making the request</li>
<li><samp>Remote_Addr</samp> - the IP address of the client
making the request</li>
<li><samp>Remote_User</samp> - the authenticated username (if
available)</li>
<li><samp>Request_Method</samp> - the name of the method
being used (<samp>GET</samp>, <samp>POST</samp>, <em>et
cetera</em>)</li>
<li><samp>Request_Protocol</samp> - the name and version of
the protocol with which the request was made (<em>e.g.</em>,
"HTTP/0.9", "HTTP/1.1", <em>etc.</em>)</li>
<li><samp>Request_URI</samp> - the portion of the URL
following the scheme and host portion</li>
</ul>
<p>Some of the more commonly used request header field names
include <samp>Host</samp>, <samp>User-Agent</samp>, and
<samp>Referer</samp>.</p>
<p>If the <em>attribute</em> name doesn't match any of the
special keywords, nor any of the request's header field names,
it is tested as the name of an environment variable in the list
of those associated with the request. This allows
<code>SetEnvIf</code> directives to test against the result of
prior matches.</p>
<blockquote>
<strong>Only those environment variables defined by earlier
<code>SetEnvIf[NoCase]</code> directives are available for
testing in this manner. 'Earlier' means that they were
defined at a broader scope (such as server-wide) or
previously in the current directive's scope.</strong>
</blockquote>
<p>Example:</p>
<pre>
SetEnvIf Request_URI "\.gif$" object_is_image=gif
SetEnvIf Request_URI "\.jpg$" object_is_image=jpg
SetEnvIf Request_URI "\.xbm$" object_is_image=xbm
:
SetEnvIf Referer www\.mydomain\.com intra_site_referral
:
SetEnvIf object_is_image xbm XBIT_PROCESSING=1
</pre>
<p>The first three will set the environment variable
<samp>object_is_image</samp> if the request was for an image
file, and the fourth sets <samp>intra_site_referral</samp> if
the referring page was somewhere on the
<samp>www.mydomain.com</samp> Web site.</p>
<hr />
<!-- the HR is part of the directive description -->
<h2><a id="setenvifnocase" name="setenvifnocase">SetEnvIfNoCase
directive</a></h2>
<p><a href="directive-dict.html#Syntax"
rel="Help"><strong>Syntax:</strong></a> SetEnvIfNoCase
<em>attribute regex env-variable</em>[=<em>value</em>]
[<em>env-variable</em>[=<em>value</em>]] ...<br />
<a href="directive-dict.html#Default"
rel="Help"><strong>Default:</strong></a> <em>none</em><br />
<a href="directive-dict.html#Context"
rel="Help"><strong>Context:</strong></a> server config, virtual
host, directory, .htaccess<br />
<a href="directive-dict.html#Override"
rel="Help"><strong>Override:</strong></a> FileInfo<br />
<a href="directive-dict.html#Status"
rel="Help"><strong>Status:</strong></a> Base<br />
<a href="directive-dict.html#Module"
rel="Help"><strong>Module:</strong></a> mod_setenvif<br />
<a href="directive-dict.html#Compatibility"
rel="Help"><strong>Compatibility:</strong></a> Apache 1.3 and
above; the Request_Protocol keyword and environment-variable
matching are only available with 1.3.7 and later; use in
.htaccess files only supported with 1.3.13 and later</p>
<p>The <samp>SetEnvIfNoCase</samp> is semantically identical to
the <a href="#setenvif"><samp>SetEnvIf</samp></a> directive,
and differs only in that the regular expression matching is
performed in a case-insensitive manner. For example:</p>
<pre>
SetEnvIfNoCase Host Apache\.Org site=apache
</pre>
<p>This will cause the <samp>site</samp> environment variable
to be set to "<samp>apache</samp>" if the HTTP request header
field <samp>Host:</samp> was included and contained
<samp>Apache.Org</samp>, <samp>apache.org</samp>, or any other
combination.</p>
<hr />
<h3 align="CENTER">Apache HTTP Server Version 1.3</h3>
<a href="./"><img src="../images/index.gif" alt="Index" /></a>
<a href="../"><img src="../images/home.gif" alt="Home" /></a>
</body>
</html>
|