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.0</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/">Documentation</a> > <a href="../">Version 2.0</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> |
26 <a href="../ko/mod/mod_setenvif.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
27 <a href="../tr/mod/mod_setenvif.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
29 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Allows the setting of environment variables based
30 on characteristics of the request</td></tr>
31 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr>
32 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>setenvif_module</td></tr>
33 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_setenvif.c</td></tr></table>
37 <p>The <code class="module"><a href="../mod/mod_setenvif.html">mod_setenvif</a></code> module allows you to set
38 environment variables according to whether different aspects of
39 the request match regular expressions you specify. These
40 environment variables can be used by other parts of the server
41 to make decisions about actions to be taken.</p>
43 <p>The directives are considered in the order they appear in
44 the configuration files. So more complex sequences can be used,
45 such as this example, which sets <code>netscape</code> if the
46 browser is mozilla but not MSIE.</p>
48 <div class="example"><p><code>
49 BrowserMatch ^Mozilla netscape<br />
50 BrowserMatch MSIE !netscape<br />
53 <div id="quickview"><h3 class="directives">Directives</h3>
55 <li><img alt="" src="../images/down.gif" /> <a href="#browsermatch">BrowserMatch</a></li>
56 <li><img alt="" src="../images/down.gif" /> <a href="#browsermatchnocase">BrowserMatchNoCase</a></li>
57 <li><img alt="" src="../images/down.gif" /> <a href="#setenvif">SetEnvIf</a></li>
58 <li><img alt="" src="../images/down.gif" /> <a href="#setenvifnocase">SetEnvIfNoCase</a></li>
62 <li><a href="../env.html">Environment Variables in Apache</a></li>
65 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
66 <div class="directive-section"><h2><a name="BrowserMatch" id="BrowserMatch">BrowserMatch</a> <a name="browsermatch" id="browsermatch">Directive</a></h2>
67 <table class="directive">
68 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables conditional on HTTP User-Agent
70 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>BrowserMatch <em>regex [!]env-variable</em>[=<em>value</em>]
71 [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr>
72 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
73 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
74 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
75 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr>
77 <p>The <code class="directive">BrowserMatch</code> is a special cases of the
78 <code class="directive"><a href="#setenvif">SetEnvIf</a></code> directive that
79 sets environment variables conditional on the
80 <code>User-Agent</code> HTTP request header. The following two
81 lines have the same effect:</p>
82 <div class="example"><p><code>
83 BrowserMatchNoCase Robot is_a_robot<br />
84 SetEnvIfNoCase User-Agent Robot is_a_robot<br />
87 <p>Some additional examples:</p>
88 <div class="example"><p><code>
89 BrowserMatch ^Mozilla forms jpeg=yes browser=netscape<br />
90 BrowserMatch "^Mozilla/[2-3]" tables agif frames javascript<br />
91 BrowserMatch MSIE !javascript<br />
95 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
96 <div class="directive-section"><h2><a name="BrowserMatchNoCase" id="BrowserMatchNoCase">BrowserMatchNoCase</a> <a name="browsermatchnocase" id="browsermatchnocase">Directive</a></h2>
97 <table class="directive">
98 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables conditional on User-Agent without
99 respect to case</td></tr>
100 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>BrowserMatchNoCase <em>regex [!]env-variable</em>[=<em>value</em>]
101 [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr>
102 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
103 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
104 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
105 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr>
106 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>Apache 1.2 and
107 above (in Apache 1.2 this directive was found in the
108 now-obsolete mod_browser module)</td></tr>
111 <p>The <code class="directive">BrowserMatchNoCase</code> directive is
112 semantically identical to the <code class="directive"><a href="#browsermatch">BrowserMatch</a></code> directive.
113 However, it provides for case-insensitive matching. For
115 <div class="example"><p><code>
116 BrowserMatchNoCase mac platform=macintosh<br />
117 BrowserMatchNoCase win platform=windows<br />
120 <p>The <code class="directive">BrowserMatch</code> and
121 <code class="directive">BrowserMatchNoCase</code> directives are special cases of
122 the <code class="directive"><a href="#setenvif">SetEnvIf</a></code> and <code class="directive"><a href="#setenvifnocase">SetEnvIfNoCase</a></code>
123 directives. The following two lines have the same effect:</p>
124 <div class="example"><p><code>
125 BrowserMatchNoCase Robot is_a_robot<br />
126 SetEnvIfNoCase User-Agent Robot is_a_robot<br />
130 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
131 <div class="directive-section"><h2><a name="SetEnvIf" id="SetEnvIf">SetEnvIf</a> <a name="setenvif" id="setenvif">Directive</a></h2>
132 <table class="directive">
133 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables based on attributes of the request
135 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>SetEnvIf <em>attribute
136 regex [!]env-variable</em>[=<em>value</em>]
137 [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr>
138 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
139 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
140 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
141 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr>
143 <p>The <code class="directive">SetEnvIf</code> directive defines
144 environment variables based on attributes of the request. The
145 <em>attribute</em> specified in the first argument can be one of three
149 <li>An HTTP request header field (see <a href="http://www.rfc-editor.org/rfc/rfc2616.txt">RFC2616</a>
150 for more information about these); for example: <code>Host</code>,
151 <code>User-Agent</code>, <code>Referer</code>, and
152 <code>Accept-Language</code>. A regular expression may be
153 used to specify a set of request headers.</li>
155 <li>One of the following aspects of the request:
157 <li><code>Remote_Host</code> - the hostname (if available) of
158 the client making the request</li>
160 <li><code>Remote_Addr</code> - the IP address of the client
161 making the request</li>
163 <li><code>Server_Addr</code> - the IP address of the server
164 on which the request was received (only with versions later
167 <li><code>Request_Method</code> - the name of the method
168 being used (<code>GET</code>, <code>POST</code>, <em>et
171 <li><code>Request_Protocol</code> - the name and version of
172 the protocol with which the request was made (<em>e.g.</em>,
173 "HTTP/0.9", "HTTP/1.1", <em>etc.</em>)</li>
175 <li><code>Request_URI</code> - the resource requested on the HTTP
176 request line -- generally the portion of the URL
177 following the scheme and host portion without the query string. See
178 the <code class="directive"><a href="../mod/mod_rewrite.html#rewritecond">RewriteCond</a></code>
179 directive of <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> for extra information on
180 how to match your query string.</li>
184 <li>The name of an environment variable in the list of those
185 associated with the request. This allows
186 <code class="directive">SetEnvIf</code> directives to test against the result
187 of prior matches. Only those environment variables defined by earlier
188 <code>SetEnvIf[NoCase]</code> directives are available for testing in
189 this manner. 'Earlier' means that they were defined at a broader scope
190 (such as server-wide) or previously in the current directive's scope.
191 Environment variables will be considered only if there was no match
192 among request characteristics and a regular expression was not
193 used for the <em>attribute</em>.</li>
196 <p>The second argument (<em>regex</em>) is a <a href="http://www.pcre.org/">Perl compatible regular expression</a>.
197 This is similar to a POSIX.2 egrep-style regular expression.
198 If the <em>regex</em> matches against the <em>attribute</em>,
199 then the remainder of the arguments are evaluated.</p>
201 <p>The rest of the arguments give the names of variables to set, and
202 optionally values to which they should be set. These take the form
206 <li><code><em>varname</em></code>, or</li>
208 <li><code>!<em>varname</em></code>, or</li>
210 <li><code><em>varname</em>=<em>value</em></code></li>
213 <p>In the first form, the value will be set to "1". The second
214 will remove the given variable if already defined, and the
215 third will set the variable to the literal value given by
216 <code><em>value</em></code>. Since version 2.0.51 Apache will
217 recognize occurrences of <code>$1</code>..<code>$9</code> within
218 <var>value</var> and replace them by parenthesized subexpressions
219 of <var>regex</var>.</p>
221 <div class="example"><h3>Example:</h3><p><code>
223 SetEnvIf Request_URI "\.gif$" object_is_image=gif<br />
224 SetEnvIf Request_URI "\.jpg$" object_is_image=jpg<br />
225 SetEnvIf Request_URI "\.xbm$" object_is_image=xbm<br />
227 SetEnvIf Referer www\.mydomain\.com intra_site_referral<br />
229 SetEnvIf object_is_image xbm XBIT_PROCESSING=1<br />
231 SetEnvIf ^TS* ^[a-z].* HAVE_TS<br />
234 <p>The first three will set the environment variable
235 <code>object_is_image</code> if the request was for an image
236 file, and the fourth sets <code>intra_site_referral</code> if
237 the referring page was somewhere on the
238 <code>www.mydomain.com</code> Web site.</p>
240 <p>The last example will set environment variable
241 <code>HAVE_TS</code> if the request contains any headers that
242 begin with "TS" whose values begins with any character in the
247 <li><a href="../env.html">Environment Variables in Apache</a>,
248 for additional examples.
252 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
253 <div class="directive-section"><h2><a name="SetEnvIfNoCase" id="SetEnvIfNoCase">SetEnvIfNoCase</a> <a name="setenvifnocase" id="setenvifnocase">Directive</a></h2>
254 <table class="directive">
255 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables based on attributes of the request
256 without respect to case</td></tr>
257 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>SetEnvIfNoCase <em>attribute regex
258 [!]env-variable</em>[=<em>value</em>]
259 [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr>
260 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
261 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr>
262 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
263 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr>
264 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>Apache 1.3 and above</td></tr>
267 <p>The <code class="directive">SetEnvIfNoCase</code> is semantically identical to
268 the <code class="directive"><a href="#setenvif">SetEnvIf</a></code> directive,
269 and differs only in that the regular expression matching is
270 performed in a case-insensitive manner. For example:</p>
271 <div class="example"><p><code>
272 SetEnvIfNoCase Host Apache\.Org site=apache
275 <p>This will cause the <code>site</code> environment variable
276 to be set to "<code>apache</code>" if the HTTP request header
277 field <code>Host:</code> was included and contained
278 <code>Apache.Org</code>, <code>apache.org</code>, or any other
283 <div class="bottomlang">
284 <p><span>Available Languages: </span><a href="../en/mod/mod_setenvif.html" title="English"> en </a> |
285 <a href="../ja/mod/mod_setenvif.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
286 <a href="../ko/mod/mod_setenvif.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
287 <a href="../tr/mod/mod_setenvif.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
288 </div><div id="footer">
289 <p class="apache">Copyright 2009 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>
290 <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>