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
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" />
12 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
14 <div id="page-header">
15 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
16 <p class="apache">Apache HTTP Server Version 2.1</p>
17 <img alt="" src="../images/feather.gif" /></div>
18 <div class="up"><a href="./"><img title="<-" alt="<-" src="../images/left.gif" /></a></div>
20 <a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs-project/">Documentation</a> > <a href="../">Version 2.1</a> > <a href="./">Modules</a></div>
21 <div id="page-content">
22 <div id="preamble"><h1>Apache Module mod_setenvif</h1>
24 <p><span>Available Languages: </span><a href="../en/mod/mod_setenvif.html" title="English"> en </a> |
25 <a href="../ja/mod/mod_setenvif.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a></p>
27 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Allows the setting of environment variables based
28 on characteristics of the request</td></tr>
29 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr>
30 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>setenvif_module</td></tr>
31 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_setenvif.c</td></tr></table>
35 <p>The <code class="module"><a href="../mod/mod_setenvif.html">mod_setenvif</a></code> 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>
46 <div class="example"><p><code>
47 BrowserMatch ^Mozilla netscape<br />
48 BrowserMatch MSIE !netscape<br />
51 <div id="quickview"><h3 class="directives">Directives</h3>
53 <li><img alt="" src="../images/down.gif" /> <a href="#browsermatch">BrowserMatch</a></li>
54 <li><img alt="" src="../images/down.gif" /> <a href="#browsermatchnocase">BrowserMatchNoCase</a></li>
55 <li><img alt="" src="../images/down.gif" /> <a href="#setenvif">SetEnvIf</a></li>
56 <li><img alt="" src="../images/down.gif" /> <a href="#setenvifnocase">SetEnvIfNoCase</a></li>
60 <li><a href="../env.html">Environment Variables in Apache</a></li>
63 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
64 <div class="directive-section"><h2><a name="BrowserMatch" id="BrowserMatch">BrowserMatch</a> <a name="browsermatch" id="browsermatch">Directive</a></h2>
65 <table class="directive">
66 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables conditional on HTTP User-Agent
68 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>BrowserMatch <em>regex [!]env-variable</em>[=<em>value</em>]
69 [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr>
70 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
71 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
72 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
73 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr>
75 <p>The <code class="directive">BrowserMatch</code> is a special cases of the
76 <code class="directive"><a href="#setenvif">SetEnvIf</a></code> directive that
77 sets environment variables conditional on the
78 <code>User-Agent</code> HTTP request header. The following two
79 lines have the same effect:</p>
80 <div class="example"><p><code>
81 BrowserMatchNoCase Robot is_a_robot<br />
82 SetEnvIfNoCase User-Agent Robot is_a_robot<br />
85 <p>Some additional examples:</p>
86 <div class="example"><p><code>
87 BrowserMatch ^Mozilla forms jpeg=yes browser=netscape<br />
88 BrowserMatch "^Mozilla/[2-3]" tables agif frames javascript<br />
89 BrowserMatch MSIE !javascript<br />
93 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
94 <div class="directive-section"><h2><a name="BrowserMatchNoCase" id="BrowserMatchNoCase">BrowserMatchNoCase</a> <a name="browsermatchnocase" id="browsermatchnocase">Directive</a></h2>
95 <table class="directive">
96 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables conditional on User-Agent without
97 respect to case</td></tr>
98 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>BrowserMatchNoCase <em>regex [!]env-variable</em>[=<em>value</em>]
99 [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr>
100 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
101 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
102 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
103 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr>
104 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>Apache 1.2 and
105 above (in Apache 1.2 this directive was found in the
106 now-obsolete mod_browser module)</td></tr>
109 <p>The <code class="directive">BrowserMatchNoCase</code> directive is
110 semantically identical to the <code class="directive"><a href="#browsermatch">BrowserMatch</a></code> directive.
111 However, it provides for case-insensitive matching. For
113 <div class="example"><p><code>
114 BrowserMatchNoCase mac platform=macintosh<br />
115 BrowserMatchNoCase win platform=windows<br />
118 <p>The <code class="directive">BrowserMatch</code> and
119 <code class="directive">BrowserMatchNoCase</code> directives are special cases of
120 the <code class="directive"><a href="#setenvif">SetEnvIf</a></code> and <code class="directive"><a href="#setenvifnocase">SetEnvIfNoCase</a></code>
121 directives. The following two lines have the same effect:</p>
122 <div class="example"><p><code>
123 BrowserMatchNoCase Robot is_a_robot<br />
124 SetEnvIfNoCase User-Agent Robot is_a_robot<br />
128 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
129 <div class="directive-section"><h2><a name="SetEnvIf" id="SetEnvIf">SetEnvIf</a> <a name="setenvif" id="setenvif">Directive</a></h2>
130 <table class="directive">
131 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables based on attributes of the request
133 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>SetEnvIf <em>attribute
134 regex [!]env-variable</em>[=<em>value</em>]
135 [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr>
136 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
137 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
138 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
139 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr>
141 <p>The <code class="directive">SetEnvIf</code> directive defines
142 environment variables based on attributes of the request. The
143 <em>attribute</em> specified in the first argument can be one of three
147 <li>An HTTP request header field (see <a href="http://www.rfc-editor.org/rfc/rfc2616.txt">RFC2616</a>
148 for more information about these); for example: <code>Host</code>,
149 <code>User-Agent</code>, <code>Referer</code>, and
150 <code>Accept-Language</code>. A regular expression may be
151 used to specify a set of request headers.</li>
153 <li>One of the following aspects of the request:
155 <li><code>Remote_Host</code> - the hostname (if available) of
156 the client making the request</li>
158 <li><code>Remote_Addr</code> - the IP address of the client
159 making the request</li>
161 <li><code>Server_Addr</code> - the IP address of the server
162 on which the request was received (only with versions later
165 <li><code>Request_Method</code> - the name of the method
166 being used (<code>GET</code>, <code>POST</code>, <em>et
169 <li><code>Request_Protocol</code> - the name and version of
170 the protocol with which the request was made (<em>e.g.</em>,
171 "HTTP/0.9", "HTTP/1.1", <em>etc.</em>)</li>
173 <li><code>Request_URI</code> - the resource requested on the HTTP
174 request line -- generally the portion of the URL
175 following the scheme and host portion without the query string</li>
179 <li>The name of an environment variable in the list of those
180 associated with the request. This allows
181 <code class="directive">SetEnvIf</code> directives to test against the result
182 of prior matches. Only those environment variables defined by earlier
183 <code>SetEnvIf[NoCase]</code> directives are available for testing in
184 this manner. 'Earlier' means that they were defined at a broader scope
185 (such as server-wide) or previously in the current directive's scope.
186 Environment variables will be considered only if there was no match
187 among request characteristics and a regular expression was not
188 used for the <em>attribute</em>.</li>
191 <p>The second argument (<em>regex</em>) is a <a href="http://www.pcre.org/">Perl compatible regular expression</a>.
192 This is similar to a POSIX.2 egrep-style regular expression.
193 If the <em>regex</em> matches against the <em>attribute</em>,
194 then the remainder of the arguments are evaluated.</p>
196 <p>The rest of the arguments give the names of variables to set, and
197 optionally values to which they should be set. These take the form
201 <li><code><em>varname</em></code>, or</li>
203 <li><code>!<em>varname</em></code>, or</li>
205 <li><code><em>varname</em>=<em>value</em></code></li>
208 <p>In the first form, the value will be set to "1". The second
209 will remove the given variable if already defined, and the
210 third will set the variable to the literal value given by
211 <code><em>value</em></code>. Since version 2.1 Apache will
212 recognize occurrences of <code>$1</code>..<code>$9</code> within
213 <var>value</var> and replace them by parenthesized subexpressions
214 of <var>regex</var>.</p>
216 <div class="example"><h3>Example:</h3><p><code>
218 SetEnvIf Request_URI "\.gif$" object_is_image=gif<br />
219 SetEnvIf Request_URI "\.jpg$" object_is_image=jpg<br />
220 SetEnvIf Request_URI "\.xbm$" object_is_image=xbm<br />
222 SetEnvIf Referer www\.mydomain\.com intra_site_referral<br />
224 SetEnvIf object_is_image xbm XBIT_PROCESSING=1<br />
226 SetEnvIf ^TS* ^[a-z].* HAVE_TS<br />
229 <p>The first three will set the environment variable
230 <code>object_is_image</code> if the request was for an image
231 file, and the fourth sets <code>intra_site_referral</code> if
232 the referring page was somewhere on the
233 <code>www.mydomain.com</code> Web site.</p>
235 <p>The last example will set environment variable
236 <code>HAVE_TS</code> if the request contains any headers that
237 begin with "TS" whose values begins with any character in the
242 <li><a href="../env.html">Environment Variables in Apache</a>,
243 for additional examples.
247 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
248 <div class="directive-section"><h2><a name="SetEnvIfNoCase" id="SetEnvIfNoCase">SetEnvIfNoCase</a> <a name="setenvifnocase" id="setenvifnocase">Directive</a></h2>
249 <table class="directive">
250 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables based on attributes of the request
251 without respect to case</td></tr>
252 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>SetEnvIfNoCase <em>attribute regex
253 [!]env-variable</em>[=<em>value</em>]
254 [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr>
255 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
256 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
257 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
258 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr>
259 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>Apache 1.3 and above</td></tr>
262 <p>The <code class="directive">SetEnvIfNoCase</code> is semantically identical to
263 the <code class="directive"><a href="#setenvif">SetEnvIf</a></code> directive,
264 and differs only in that the regular expression matching is
265 performed in a case-insensitive manner. For example:</p>
266 <div class="example"><p><code>
267 SetEnvIfNoCase Host Apache\.Org site=apache
270 <p>This will cause the <code>site</code> environment variable
271 to be set to "<code>apache</code>" if the HTTP request header
272 field <code>Host:</code> was included and contained
273 <code>Apache.Org</code>, <code>apache.org</code>, or any other
278 <div class="bottomlang">
279 <p><span>Available Languages: </span><a href="../en/mod/mod_setenvif.html" title="English"> en </a> |
280 <a href="../ja/mod/mod_setenvif.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a></p>
281 </div><div id="footer">
282 <p class="apache">Copyright 1999-2004 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>
283 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>