]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_setenvif.html.en
xforms
[apache] / docs / manual / mod / mod_setenvif.html.en
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5               This file is generated from xml source: DO NOT EDIT
6         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7       -->
8 <title>mod_setenvif - Apache HTTP Server</title>
9 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
12 <script src="../style/scripts/prettify.js" type="text/javascript">
13 </script>
14
15 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
16 <body>
17 <div id="page-header">
18 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
19 <p class="apache">Apache HTTP Server Version 2.5</p>
20 <img alt="" src="../images/feather.gif" /></div>
21 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
22 <div id="path">
23 <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.5</a> &gt; <a href="./">Modules</a></div>
24 <div id="page-content">
25 <div id="preamble"><h1>Apache Module mod_setenvif</h1>
26 <div class="toplang">
27 <p><span>Available Languages: </span><a href="../en/mod/mod_setenvif.html" title="English">&nbsp;en&nbsp;</a> |
28 <a href="../fr/mod/mod_setenvif.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
29 <a href="../ja/mod/mod_setenvif.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
30 <a href="../ko/mod/mod_setenvif.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
31 <a href="../tr/mod/mod_setenvif.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
32 </div>
33 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Allows the setting of environment variables based
34 on characteristics of the request</td></tr>
35 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr>
36 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>setenvif_module</td></tr>
37 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_setenvif.c</td></tr></table>
38 <h3>Summary</h3>
39
40
41     <p>The <code class="module"><a href="../mod/mod_setenvif.html">mod_setenvif</a></code> module allows you to set
42     internal environment variables according to whether different aspects of
43     the request match regular expressions you specify. These
44     environment variables can be used by other parts of the server
45     to make decisions about actions to be taken, as well as becoming
46     available to CGI scripts and SSI pages.</p>
47
48     <p>The directives are considered in the order they appear in
49     the configuration files. So more complex sequences can be used,
50     such as this example, which sets <code>netscape</code> if the
51     browser is mozilla but not MSIE.</p>
52
53 <pre class="prettyprint lang-config">
54 BrowserMatch ^Mozilla netscape
55 BrowserMatch MSIE !netscape
56 </pre>
57
58 </div>
59 <div id="quickview"><h3 class="directives">Directives</h3>
60 <ul id="toc">
61 <li><img alt="" src="../images/down.gif" /> <a href="#browsermatch">BrowserMatch</a></li>
62 <li><img alt="" src="../images/down.gif" /> <a href="#browsermatchnocase">BrowserMatchNoCase</a></li>
63 <li><img alt="" src="../images/down.gif" /> <a href="#setenvif">SetEnvIf</a></li>
64 <li><img alt="" src="../images/down.gif" /> <a href="#setenvifexpr">SetEnvIfExpr</a></li>
65 <li><img alt="" src="../images/down.gif" /> <a href="#setenvifnocase">SetEnvIfNoCase</a></li>
66 </ul>
67 <h3>See also</h3>
68 <ul class="seealso">
69 <li><a href="../env.html">Environment Variables in Apache HTTP Server</a></li>
70 </ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
71
72 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
73 <div class="directive-section"><h2><a name="BrowserMatch" id="BrowserMatch">BrowserMatch</a> <a name="browsermatch" id="browsermatch">Directive</a></h2>
74 <table class="directive">
75 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables conditional on HTTP User-Agent
76 </td></tr>
77 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>BrowserMatch <em>regex [!]env-variable</em>[=<em>value</em>]
78 [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr>
79 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
80 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
81 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
82 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr>
83 </table>
84   <p>The <code class="directive">BrowserMatch</code> is a special cases of the
85   <code class="directive"><a href="#setenvif">SetEnvIf</a></code> directive that
86   sets environment variables conditional on the
87   <code>User-Agent</code> HTTP request header.  The following two
88   lines have the same effect:</p>
89 <pre class="prettyprint lang-config">
90 BrowserMatchNoCase Robot is_a_robot
91 SetEnvIfNoCase User-Agent Robot is_a_robot
92 </pre>
93
94
95     <p>Some additional examples:</p>
96 <pre class="prettyprint lang-config">
97 BrowserMatch ^Mozilla forms jpeg=yes browser=netscape
98 BrowserMatch "^Mozilla/[2-3]" tables agif frames javascript
99 BrowserMatch MSIE !javascript
100 </pre>
101
102
103 </div>
104 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
105 <div class="directive-section"><h2><a name="BrowserMatchNoCase" id="BrowserMatchNoCase">BrowserMatchNoCase</a> <a name="browsermatchnocase" id="browsermatchnocase">Directive</a></h2>
106 <table class="directive">
107 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables conditional on User-Agent without
108 respect to case</td></tr>
109 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>BrowserMatchNoCase  <em>regex [!]env-variable</em>[=<em>value</em>]
110     [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr>
111 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
112 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
113 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
114 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr>
115 </table>
116
117     <p>The <code class="directive">BrowserMatchNoCase</code> directive is
118     semantically identical to the <code class="directive"><a href="#browsermatch">BrowserMatch</a></code> directive.
119     However, it provides for case-insensitive matching. For
120     example:</p>
121 <pre class="prettyprint lang-config">
122 BrowserMatchNoCase mac platform=macintosh
123 BrowserMatchNoCase win platform=windows
124 </pre>
125
126
127     <p>The <code class="directive">BrowserMatch</code> and
128     <code class="directive">BrowserMatchNoCase</code> directives are special cases of
129     the <code class="directive"><a href="#setenvif">SetEnvIf</a></code> and <code class="directive"><a href="#setenvifnocase">SetEnvIfNoCase</a></code>
130     directives. The following two lines have the same effect:</p>
131 <pre class="prettyprint lang-config">
132 BrowserMatchNoCase Robot is_a_robot
133 SetEnvIfNoCase User-Agent Robot is_a_robot
134 </pre>
135
136
137 </div>
138 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
139 <div class="directive-section"><h2><a name="SetEnvIf" id="SetEnvIf">SetEnvIf</a> <a name="setenvif" id="setenvif">Directive</a></h2>
140 <table class="directive">
141 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables based on attributes of the request
142 </td></tr>
143 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>SetEnvIf <em>attribute
144     regex [!]env-variable</em>[=<em>value</em>]
145     [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr>
146 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
147 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
148 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
149 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr>
150 </table>
151     <p>The <code class="directive">SetEnvIf</code> directive defines
152     environment variables based on attributes of the request. The
153     <em>attribute</em> specified in the first argument can be one of four
154     things:</p>
155
156 <ol>
157 <li>An HTTP request header field (see <a href="http://www.rfc-editor.org/rfc/rfc2616.txt">RFC2616</a>
158     for more information about these); for example: <code>Host</code>,
159     <code>User-Agent</code>, <code>Referer</code>, and
160     <code>Accept-Language</code>.  A regular expression may be
161     used to specify a set of request headers.</li>
162
163 <li>One of the following aspects of the request:
164     <ul>
165       <li><code>Remote_Host</code> - the hostname (if available) of
166       the client making the request</li>
167
168       <li><code>Remote_Addr</code> - the IP address of the client
169       making the request</li>
170
171       <li><code>Server_Addr</code> - the IP address of the server
172       on which the request was received (only with versions later
173       than 2.0.43)</li>
174
175       <li><code>Request_Method</code> - the name of the method
176       being used (<code>GET</code>, <code>POST</code>, <em>et
177       cetera</em>)</li>
178
179       <li><code>Request_Protocol</code> - the name and version of
180       the protocol with which the request was made (<em>e.g.</em>,
181       "HTTP/0.9", "HTTP/1.1", <em>etc.</em>)</li>
182
183       <li><code>Request_URI</code> - the resource requested on the HTTP
184        request line -- generally the portion of the URL
185       following the scheme and host portion without the query string. See
186       the <code class="directive"><a href="../mod/mod_rewrite.html#rewritecond">RewriteCond</a></code>
187       directive of <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> for extra information on
188       how to match your query string.</li>
189     </ul>
190 </li>
191
192 <li>The name of an environment variable in the list of those
193 associated with the request. This allows
194 <code class="directive">SetEnvIf</code> directives to test against the result
195 of prior matches. Only those environment variables defined by earlier
196 <code>SetEnvIf[NoCase]</code> directives are available for testing in
197 this manner. 'Earlier' means that they were defined at a broader scope
198 (such as server-wide) or previously in the current directive's scope.
199 Environment variables will be considered only if there was no match
200 among request characteristics and a regular expression was not
201 used for the <em>attribute</em>.</li>
202
203 </ol>
204
205 <p>The second argument (<em>regex</em>) is a <a class="glossarylink" href="../glossary.html#regex" title="see glossary">regular expression</a>.  If the <em>regex</em>
206 matches against the <em>attribute</em>, then the remainder of the
207 arguments are evaluated.</p>
208
209 <p>The rest of the arguments give the names of variables to set, and
210 optionally values to which they should be set. These take the form
211 of</p>
212
213     <ol>
214       <li><code><em>varname</em></code>, or</li>
215
216       <li><code>!<em>varname</em></code>, or</li>
217
218       <li><code><em>varname</em>=<em>value</em></code></li>
219     </ol>
220
221     <p>In the first form, the value will be set to "1". The second
222     will remove the given variable if already defined, and the
223     third will set the variable to the literal value given by
224     <code><em>value</em></code>. Since version 2.0.51, Apache httpd will
225     recognize occurrences of <code>$1</code>..<code>$9</code> within
226     <var>value</var> and replace them by parenthesized subexpressions
227     of <var>regex</var>.</p>
228
229 <pre class="prettyprint lang-config">
230 SetEnvIf Request_URI "\.gif$" object_is_image=gif
231 SetEnvIf Request_URI "\.jpg$" object_is_image=jpg
232 SetEnvIf Request_URI "\.xbm$" object_is_image=xbm
233     
234 SetEnvIf Referer www\.mydomain\.example\.com intra_site_referral
235     
236 SetEnvIf object_is_image xbm XBIT_PROCESSING=1
237     
238 SetEnvIf ^TS  ^[a-z]  HAVE_TS
239 </pre>
240
241
242     <p>The first three will set the environment variable
243     <code>object_is_image</code> if the request was for an image
244     file, and the fourth sets <code>intra_site_referral</code> if
245     the referring page was somewhere on the
246     <code>www.mydomain.example.com</code> Web site.</p>
247
248     <p>The last example will set environment variable
249     <code>HAVE_TS</code> if the request contains any headers that
250     begin with "TS" whose values begins with any character in the
251     set [a-z].</p>
252
253 <h3>See also</h3>
254 <ul>
255 <li><a href="../env.html">Environment Variables in Apache HTTP Server</a>,
256 for additional examples.
257 </li>
258 </ul>
259 </div>
260 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
261 <div class="directive-section"><h2><a name="SetEnvIfExpr" id="SetEnvIfExpr">SetEnvIfExpr</a> <a name="setenvifexpr" id="setenvifexpr">Directive</a></h2>
262 <table class="directive">
263 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables based on an ap_expr expression</td></tr>
264 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>SetEnvIfExpr <em>expr
265     [!]env-variable</em>[=<em>value</em>]
266     [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr>
267 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
268 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
269 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
270 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr>
271 </table>
272     <p>The <code class="directive">SetEnvIfExpr</code> directive defines
273     environment variables based on an <code class="directive">&lt;If&gt;</code>
274     <code>ap_expr</code>. These expressions will be evaluated at runtime,
275     and applied <em>env-variable</em> in the same fashion as <code class="directive">SetEnvIf</code>.</p>
276
277 <pre class="prettyprint lang-config">
278     SetEnvIfExpr "tolower(req('X-Sendfile')) == 'd:\images\very_big.iso')" iso_delivered
279 </pre>
280
281
282     <p>This would set the environment variable <code>iso_delivered</code>
283     every time our application attempts to send it via <code>X-Sendfile</code></p>
284
285     <p>A more useful example would be to set the variable rfc1918 if the
286     remote IP address is a private address according to RFC 1918:</p>
287
288 <pre class="prettyprint lang-config">
289     SetEnvIfExpr "-R '10.0.0.0/8' || -R '172.16.0.0/12' || -R '192.168.0.0/16'" rfc1918
290 </pre>
291
292
293 <h3>See also</h3>
294 <ul>
295 <li><a href="../expr.html">Expressions in Apache HTTP Server</a>,
296 for a complete reference and more examples.</li>
297 <li><code class="directive">&lt;If&gt;</code> can be used to achieve similar
298 results.</li>
299 <li><code class="module"><a href="../mod/mod_filter.html">mod_filter</a></code></li>
300 </ul>
301 </div>
302 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
303 <div class="directive-section"><h2><a name="SetEnvIfNoCase" id="SetEnvIfNoCase">SetEnvIfNoCase</a> <a name="setenvifnocase" id="setenvifnocase">Directive</a></h2>
304 <table class="directive">
305 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables based on attributes of the request
306 without respect to case</td></tr>
307 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>SetEnvIfNoCase <em>attribute regex
308         [!]env-variable</em>[=<em>value</em>]
309     [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr>
310 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
311 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
312 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
313 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr>
314 </table>
315
316     <p>The <code class="directive">SetEnvIfNoCase</code> is semantically identical to
317     the <code class="directive"><a href="#setenvif">SetEnvIf</a></code> directive,
318     and differs only in that the regular expression matching is
319     performed in a case-insensitive manner. For example:</p>
320 <pre class="prettyprint lang-config">
321    SetEnvIfNoCase Host Example\.Org site=example
322 </pre>
323
324
325     <p>This will cause the <code>site</code> environment variable
326     to be set to "<code>example</code>" if the HTTP request header
327     field <code>Host:</code> was included and contained
328     <code>Example.Org</code>, <code>example.org</code>, or any other
329     combination.</p>
330
331 </div>
332 </div>
333 <div class="bottomlang">
334 <p><span>Available Languages: </span><a href="../en/mod/mod_setenvif.html" title="English">&nbsp;en&nbsp;</a> |
335 <a href="../fr/mod/mod_setenvif.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
336 <a href="../ja/mod/mod_setenvif.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
337 <a href="../ko/mod/mod_setenvif.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
338 <a href="../tr/mod/mod_setenvif.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
339 </div><div class="top"><a href="#page-header"><img src="../images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&amp;A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div>
340 <script type="text/javascript"><!--//--><![CDATA[//><!--
341 var comments_shortname = 'httpd';
342 var comments_identifier = 'http://httpd.apache.org/docs/trunk/mod/mod_setenvif.html';
343 (function(w, d) {
344     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
345         d.write('<div id="comments_thread"><\/div>');
346         var s = d.createElement('script');
347         s.type = 'text/javascript';
348         s.async = true;
349         s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
350         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
351     }
352     else {
353         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
354     }
355 })(window, document);
356 //--><!]]></script></div><div id="footer">
357 <p class="apache">Copyright 2013 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
358 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/quickreference.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!--
359 if (typeof(prettyPrint) !== 'undefined') {
360     prettyPrint();
361 }
362 //--><!]]></script>
363 </body></html>