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