summaryrefslogtreecommitdiff
path: root/usr.sbin/httpd/htdocs/manual/mod/mod_setenvif.html
blob: d199f0c177d021c32d49f870eec316469e9d26b3 (plain)
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
 <HEAD>
  <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 is contained in the <SAMP>mod_setenvif.c</SAMP> file, and
  <STRONG>is</STRONG> compiled in by default. It provides for
  the ability to set environment variables based upon attributes of the
  request.
  </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
  regular expressions you specify.  These envariables 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.
  <BLOCKQUOTE><PRE>
  BrowserMatch ^Mozilla netscape
  BrowserMatch MSIE !netscape
  </PRE></BLOCKQUOTE>
  </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 NAME="BrowserMatch">The <SAMP>BrowserMatch</SAMP> Directive</A></H2>
  <P>
  <A
   HREF="directive-dict.html#Syntax"
   REL="Help"
  ><STRONG>Syntax:</STRONG></A> BrowserMatch <EM>regex envar[=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
  <BR>
  <A
   HREF="directive-dict.html#Override"
   REL="Help"
  ><STRONG>Override:</STRONG></A> <EM>none</EM>
  <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 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 &quot;1&quot;. 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 cane-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 NAME="BrowserMatchNoCase">
    The <SAMP>BrowserMatchNoCase</SAMP> Directive
   </A>
  </H2>
  <P>
  <A
   HREF="directive-dict.html#Syntax"
   REL="Help"
  ><STRONG>Syntax:</STRONG></A> BrowserMatchNoCase <EM>regex envar[=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
  <BR>
  <A
   HREF="directive-dict.html#Override"
   REL="Help"
  ><STRONG>Override:</STRONG></A> <EM>none</EM>
  <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 NAME="SetEnvIf">
    The <SAMP>SetEnvIf</SAMP> Directive
   </A>
  </H2>
  <P>
  <A
   HREF="directive-dict.html#Syntax"
   REL="Help"
  ><STRONG>Syntax:</STRONG></A> SetEnvIf <EM> attribute regex envar[=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
  <BR>
  <A
   HREF="directive-dict.html#Override"
   REL="Help"
  ><STRONG>Override:</STRONG></A> <EM>none</EM>
  <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
  </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://ds.internic.net/rfc/rfc2068.txt"
  >RFC2068</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 envariable <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 NAME="SetEnvIfNoCase">
    The <SAMP>SetEnvIfNoCase</SAMP> Directive
   </A>
  </H2>
  <P>
  <A
   HREF="directive-dict.html#Syntax"
   REL="Help"
  ><STRONG>Syntax:</STRONG></A> SetEnvIfNoCase
   <EM> attribute regex envar[=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
  <BR>
  <A
   HREF="directive-dict.html#Override"
   REL="Help"
  ><STRONG>Override:</STRONG></A> <EM>none</EM>
  <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
  </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> envariable to be set to
  &quot;<SAMP>apache</SAMP>&quot; 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>