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/directives.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.2</p> 20<img alt="" src="/images/feather.gif" /></div> 21<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div> 22<div id="path"> 23<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.2</a> > <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"> en </a> | 28<a href="/ja/mod/mod_setenvif.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 29<a href="/ko/mod/mod_setenvif.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 30<a href="/tr/mod/mod_setenvif.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 31</div> 32<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Allows the setting of environment variables based 33on characteristics of the request</td></tr> 34<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr> 35<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>setenvif_module</td></tr> 36<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_setenvif.c</td></tr></table> 37<h3>Summary</h3> 38 39 40 <p>The <code class="module"><a href="/mod/mod_setenvif.html">mod_setenvif</a></code> module allows you to set 41 internal environment variables according to whether different aspects of 42 the request match regular expressions you specify. These 43 environment variables can be used by other parts of the server 44 to make decisions about actions to be taken, as well as becoming 45 available to CGI scripts and SSI pages.</p> 46 47 <p>The directives are considered in the order they appear in 48 the configuration files. So more complex sequences can be used, 49 such as this example, which sets <code>netscape</code> if the 50 browser is mozilla but not MSIE.</p> 51 52<div class="example"><p><code> 53 BrowserMatch ^Mozilla netscape<br /> 54 BrowserMatch MSIE !netscape<br /> 55</code></p></div> 56</div> 57<div id="quickview"><h3 class="directives">Directives</h3> 58<ul id="toc"> 59<li><img alt="" src="/images/down.gif" /> <a href="#browsermatch">BrowserMatch</a></li> 60<li><img alt="" src="/images/down.gif" /> <a href="#browsermatchnocase">BrowserMatchNoCase</a></li> 61<li><img alt="" src="/images/down.gif" /> <a href="#setenvif">SetEnvIf</a></li> 62<li><img alt="" src="/images/down.gif" /> <a href="#setenvifnocase">SetEnvIfNoCase</a></li> 63</ul> 64<h3>See also</h3> 65<ul class="seealso"> 66<li><a href="/env.html">Environment Variables in Apache</a></li> 67</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div> 68 69<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 70<div class="directive-section"><h2><a name="BrowserMatch" id="BrowserMatch">BrowserMatch</a> <a name="browsermatch" id="browsermatch">Directive</a></h2> 71<table class="directive"> 72<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables conditional on HTTP User-Agent 73</td></tr> 74<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>BrowserMatch <em>regex [!]env-variable</em>[=<em>value</em>] 75[[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr> 76<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr> 77<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr> 78<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr> 79<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr> 80</table> 81 <p>The <code class="directive">BrowserMatch</code> is a special cases of the 82 <code class="directive"><a href="#setenvif">SetEnvIf</a></code> directive that 83 sets environment variables conditional on the 84 <code>User-Agent</code> HTTP request header. The following two 85 lines have the same effect:</p> 86<div class="example"><p><code> 87 BrowserMatchNoCase Robot is_a_robot<br /> 88 SetEnvIfNoCase User-Agent Robot is_a_robot<br /> 89</code></p></div> 90 91 <p>Some additional examples:</p> 92<div class="example"><p><code> 93 BrowserMatch ^Mozilla forms jpeg=yes browser=netscape<br /> 94 BrowserMatch "^Mozilla/[2-3]" tables agif frames javascript<br /> 95 BrowserMatch MSIE !javascript<br /> 96</code></p></div> 97 98</div> 99<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 100<div class="directive-section"><h2><a name="BrowserMatchNoCase" id="BrowserMatchNoCase">BrowserMatchNoCase</a> <a name="browsermatchnocase" id="browsermatchnocase">Directive</a></h2> 101<table class="directive"> 102<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables conditional on User-Agent without 103respect to case</td></tr> 104<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>BrowserMatchNoCase <em>regex [!]env-variable</em>[=<em>value</em>] 105 [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr> 106<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr> 107<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr> 108<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr> 109<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr> 110</table> 111 112 <p>The <code class="directive">BrowserMatchNoCase</code> directive is 113 semantically identical to the <code class="directive"><a href="#browsermatch">BrowserMatch</a></code> directive. 114 However, it provides for case-insensitive matching. For 115 example:</p> 116<div class="example"><p><code> 117 BrowserMatchNoCase mac platform=macintosh<br /> 118 BrowserMatchNoCase win platform=windows<br /> 119</code></p></div> 120 121 <p>The <code class="directive">BrowserMatch</code> and 122 <code class="directive">BrowserMatchNoCase</code> directives are special cases of 123 the <code class="directive"><a href="#setenvif">SetEnvIf</a></code> and <code class="directive"><a href="#setenvifnocase">SetEnvIfNoCase</a></code> 124 directives. The following two lines have the same effect:</p> 125<div class="example"><p><code> 126 BrowserMatchNoCase Robot is_a_robot<br /> 127 SetEnvIfNoCase User-Agent Robot is_a_robot<br /> 128</code></p></div> 129 130</div> 131<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 132<div class="directive-section"><h2><a name="SetEnvIf" id="SetEnvIf">SetEnvIf</a> <a name="setenvif" id="setenvif">Directive</a></h2> 133<table class="directive"> 134<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Sets environment variables based on attributes of the request 135</td></tr> 136<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>SetEnvIf <em>attribute 137 regex [!]env-variable</em>[=<em>value</em>] 138 [[!]<em>env-variable</em>[=<em>value</em>]] ...</code></td></tr> 139<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr> 140<tr><th><a href="directive-dict.html#Override">Override:</a></th><td>FileInfo</td></tr> 141<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr> 142<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_setenvif</td></tr> 143</table> 144 <p>The <code class="directive">SetEnvIf</code> directive defines 145 environment variables based on attributes of the request. The 146 <em>attribute</em> specified in the first argument can be one of three 147 things:</p> 148 149<ol> 150<li>An HTTP request header field (see <a href="http://www.rfc-editor.org/rfc/rfc2616.txt">RFC2616</a> 151 for more information about these); for example: <code>Host</code>, 152 <code>User-Agent</code>, <code>Referer</code>, and 153 <code>Accept-Language</code>. A regular expression may be 154 used to specify a set of request headers.</li> 155 156<li>One of the following aspects of the request: 157 <ul> 158 <li><code>Remote_Host</code> - the hostname (if available) of 159 the client making the request</li> 160 161 <li><code>Remote_Addr</code> - the IP address of the client 162 making the request</li> 163 164 <li><code>Server_Addr</code> - the IP address of the server 165 on which the request was received (only with versions later 166 than 2.0.43)</li> 167 168 <li><code>Request_Method</code> - the name of the method 169 being used (<code>GET</code>, <code>POST</code>, <em>et 170 cetera</em>)</li> 171 172 <li><code>Request_Protocol</code> - the name and version of 173 the protocol with which the request was made (<em>e.g.</em>, 174 "HTTP/0.9", "HTTP/1.1", <em>etc.</em>)</li> 175 176 <li><code>Request_URI</code> - the resource requested on the HTTP 177 request line -- generally the portion of the URL 178 following the scheme and host portion without the query string. See 179 the <code class="directive"><a href="/mod/mod_rewrite.html#rewritecond">RewriteCond</a></code> 180 directive of <code class="module"><a href="/mod/mod_rewrite.html">mod_rewrite</a></code> for extra information on 181 how to match your query string.</li> 182 </ul> 183</li> 184 185<li>The name of an environment variable in the list of those 186associated with the request. This allows 187<code class="directive">SetEnvIf</code> directives to test against the result 188of prior matches. Only those environment variables defined by earlier 189<code>SetEnvIf[NoCase]</code> directives are available for testing in 190this manner. 'Earlier' means that they were defined at a broader scope 191(such as server-wide) or previously in the current directive's scope. 192Environment variables will be considered only if there was no match 193among request characteristics and a regular expression was not 194used for the <em>attribute</em>.</li> 195</ol> 196 197<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> 198matches against the <em>attribute</em>, then the remainder of the 199arguments are evaluated.</p> 200 201<p>The rest of the arguments give the names of variables to set, and 202optionally values to which they should be set. These take the form 203of</p> 204 205 <ol> 206 <li><code><em>varname</em></code>, or</li> 207 208 <li><code>!<em>varname</em></code>, or</li> 209 210 <li><code><em>varname</em>=<em>value</em></code></li> 211 </ol> 212 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> 220 221<div class="example"><h3>Example:</h3><p><code> 222 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 /> 226 :<br /> 227 SetEnvIf Referer www\.mydomain\.example\.com intra_site_referral<br /> 228 :<br /> 229 SetEnvIf object_is_image xbm XBIT_PROCESSING=1<br /> 230 :<br /> 231 SetEnvIf ^TS* ^[a-z].* HAVE_TS<br /> 232</code></p></div> 233 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.example.com</code> Web site.</p> 239 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 243 set [a-z].</p> 244 245<h3>See also</h3> 246<ul> 247<li><a href="/env.html">Environment Variables in Apache</a>, 248for additional examples. 249</li> 250</ul> 251</div> 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 256without 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</table> 265 266 <p>The <code class="directive">SetEnvIfNoCase</code> is semantically identical to 267 the <code class="directive"><a href="#setenvif">SetEnvIf</a></code> directive, 268 and differs only in that the regular expression matching is 269 performed in a case-insensitive manner. For example:</p> 270<div class="example"><p><code> 271 SetEnvIfNoCase Host Apache\.Org site=apache 272</code></p></div> 273 274 <p>This will cause the <code>site</code> environment variable 275 to be set to "<code>apache</code>" if the HTTP request header 276 field <code>Host:</code> was included and contained 277 <code>Apache.Org</code>, <code>apache.org</code>, or any other 278 combination.</p> 279 280</div> 281</div> 282<div class="bottomlang"> 283<p><span>Available Languages: </span><a href="/en/mod/mod_setenvif.html" title="English"> en </a> | 284<a href="/ja/mod/mod_setenvif.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 285<a href="/ko/mod/mod_setenvif.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 286<a href="/tr/mod/mod_setenvif.html" hreflang="tr" rel="alternate" title="T�rk�e"> tr </a></p> 287</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&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> 288<script type="text/javascript"><!--//--><![CDATA[//><!-- 289var comments_shortname = 'httpd'; 290var comments_identifier = 'http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html'; 291(function(w, d) { 292 if (w.location.hostname.toLowerCase() == "httpd.apache.org") { 293 d.write('<div id="comments_thread"><\/div>'); 294 var s = d.createElement('script'); 295 s.type = 'text/javascript'; 296 s.async = true; 297 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; 298 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); 299 } 300 else { 301 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); 302 } 303})(window, document); 304//--><!]]></script></div><div id="footer"> 305<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> 306<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.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[//><!-- 307if (typeof(prettyPrint) !== 'undefined') { 308 prettyPrint(); 309} 310//--><!]]></script> 311</body></html>