github.com/krum110487/go-htaccess@v0.0.0-20240316004156-60641c8e7598/tests/data/apache_2_2_34/manual/sections.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>Configuration Sections - 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/sections.html" rel="canonical" /></head> 18 <body id="manual-page"><div id="page-header"> 19 <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> 20 <p class="apache">Apache HTTP Server Version 2.2</p> 21 <img alt="" src="./images/feather.gif" /></div> 22 <div class="up"><a href="./"><img title="<-" alt="<-" src="./images/left.gif" /></a></div> 23 <div id="path"> 24 <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></div><div id="page-content"><div class="retired"><h4>Please note</h4> 25 <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> 26 <p>You may follow <a href="http://httpd.apache.org/docs/current/sections.html">this link</a> to go to the current version of this document.</p></div><div id="preamble"><h1>Configuration Sections</h1> 27 <div class="toplang"> 28 <p><span>Available Languages: </span><a href="./en/sections.html" title="English"> en </a> | 29 <a href="./fr/sections.html" hreflang="fr" rel="alternate" title="Français"> fr </a> | 30 <a href="./ja/sections.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 31 <a href="./ko/sections.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 32 <a href="./tr/sections.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p> 33 </div> 34 <p>Directives in the <a href="configuring.html">configuration files</a> may apply to the 35 entire server, or they may be restricted to apply only to particular 36 directories, files, hosts, or URLs. This document describes how to 37 use configuration section containers or <code>.htaccess</code> files 38 to change the scope of other configuration directives.</p> 39 </div> 40 <div id="quickview"><ul id="toc"><li><img alt="" src="./images/down.gif" /> <a href="#types">Types of Configuration Section Containers</a></li> 41 <li><img alt="" src="./images/down.gif" /> <a href="#file-and-web">Filesystem and Webspace</a></li> 42 <li><img alt="" src="./images/down.gif" /> <a href="#virtualhost">Virtual Hosts</a></li> 43 <li><img alt="" src="./images/down.gif" /> <a href="#proxy">Proxy</a></li> 44 <li><img alt="" src="./images/down.gif" /> <a href="#whatwhere">What Directives are Allowed?</a></li> 45 <li><img alt="" src="./images/down.gif" /> <a href="#mergin">How the sections are merged</a></li> 46 </ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div> 47 <div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div> 48 <div class="section"> 49 <h2><a name="types" id="types">Types of Configuration Section Containers</a></h2> 50 51 <table class="related"><tr><th>Related Modules</th><th>Related Directives</th></tr><tr><td><ul><li><code class="module"><a href="./mod/core.html">core</a></code></li><li><code class="module"><a href="./mod/mod_version.html">mod_version</a></code></li><li><code class="module"><a href="./mod/mod_proxy.html">mod_proxy</a></code></li></ul></td><td><ul><li><code class="directive"><a href="./mod/core.html#directory"><Directory></a></code></li><li><code class="directive"><a href="./mod/core.html#directorymatch"><DirectoryMatch></a></code></li><li><code class="directive"><a href="./mod/core.html#files"><Files></a></code></li><li><code class="directive"><a href="./mod/core.html#filesmatch"><FilesMatch></a></code></li><li><code class="directive"><a href="./mod/core.html#ifdefine"><IfDefine></a></code></li><li><code class="directive"><a href="./mod/core.html#ifmodule"><IfModule></a></code></li><li><code class="directive"><a href="./mod/mod_version.html#ifversion"><IfVersion></a></code></li><li><code class="directive"><a href="./mod/core.html#location"><Location></a></code></li><li><code class="directive"><a href="./mod/core.html#locationmatch"><LocationMatch></a></code></li><li><code class="directive"><a href="./mod/mod_proxy.html#proxy"><Proxy></a></code></li><li><code class="directive"><a href="./mod/mod_proxy.html#proxymatch"><ProxyMatch></a></code></li><li><code class="directive"><a href="./mod/core.html#virtualhost"><VirtualHost></a></code></li></ul></td></tr></table> 52 53 <p>There are two basic types of containers. Most containers are 54 evaluated for each request. The enclosed directives are applied only 55 for those requests that match the containers. The <code class="directive"><a href="./mod/core.html#ifdefine"><IfDefine></a></code>, <code class="directive"><a href="./mod/core.html#ifmodule"><IfModule></a></code>, and 56 <code class="directive"><a href="./mod/mod_version.html#ifversion"><IfVersion></a></code> 57 containers, on the other hand, are evaluated only at server startup 58 and restart. If their conditions are true at startup, then the 59 enclosed directives will apply to all requests. If the conditions are 60 not true, the enclosed directives will be ignored.</p> 61 62 <p>The <code class="directive"><a href="./mod/core.html#ifdefine"><IfDefine></a></code> directive 63 encloses directives that will only be applied if an appropriate 64 parameter is defined on the <code class="program"><a href="./programs/httpd.html">httpd</a></code> command line. For example, 65 with the following configuration, all requests will be redirected 66 to another site only if the server is started using 67 <code>httpd -DClosedForNow</code>:</p> 68 69 <pre class="prettyprint lang-config"><IfDefine ClosedForNow> 70 Redirect / http://otherserver.example.com/ 71 </IfDefine></pre> 72 73 74 <p>The <code class="directive"><a href="./mod/core.html#ifmodule"><IfModule></a></code> 75 directive is very similar, except it encloses directives that will 76 only be applied if a particular module is available in the server. 77 The module must either be statically compiled in the server, or it 78 must be dynamically compiled and its <code class="directive"><a href="./mod/mod_so.html#loadmodule">LoadModule</a></code> line must be earlier in the 79 configuration file. This directive should only be used if you need 80 your configuration file to work whether or not certain modules are 81 installed. It should not be used to enclose directives that you want 82 to work all the time, because it can suppress useful error messages 83 about missing modules.</p> 84 85 <p>In the following example, the <code class="directive"><a href="./mod/mod_mime_magic.html#mimemagicfile">MimeMagicFile</a></code> directive will be 86 applied only if <code class="module"><a href="./mod/mod_mime_magic.html">mod_mime_magic</a></code> is available.</p> 87 88 <pre class="prettyprint lang-config"><IfModule mod_mime_magic.c> 89 MimeMagicFile conf/magic 90 </IfModule></pre> 91 92 93 <p>The <code class="directive"><a href="./mod/mod_version.html#ifversion"><IfVersion></a></code> 94 directive is very similar to <code class="directive"><a href="./mod/core.html#ifdefine"><IfDefine></a></code> and <code class="directive"><a href="./mod/core.html#ifmodule"><IfModule></a></code>, except it encloses directives that will 95 only be applied if a particular version of the server is executing. This 96 module is designed for the use in test suites and large networks which have to 97 deal with different httpd versions and different configurations.</p> 98 99 <pre class="prettyprint lang-config"><IfVersion >= 2.1> 100 # this happens only in versions greater or 101 # equal 2.1.0. 102 </IfVersion></pre> 103 104 105 <p><code class="directive"><a href="./mod/core.html#ifdefine"><IfDefine></a></code>, 106 <code class="directive"><a href="./mod/core.html#ifmodule"><IfModule></a></code>, and the 107 <code class="directive"><a href="./mod/mod_version.html#ifversion"><IfVersion></a></code> 108 can apply negative conditions by preceding their test with "!". 109 Also, these sections can be nested to achieve more complex 110 restrictions.</p> 111 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div> 112 <div class="section"> 113 <h2><a name="file-and-web" id="file-and-web">Filesystem and Webspace</a></h2> 114 115 <p>The most commonly used configuration section containers are the 116 ones that change the configuration of particular places in the 117 filesystem or webspace. First, it is important to understand the 118 difference between the two. The filesystem is the view of your disks 119 as seen by your operating system. For example, in a default install, 120 Apache resides at <code>/usr/local/apache2</code> in the Unix 121 filesystem or <code>"c:/Program Files/Apache Group/Apache2"</code> in 122 the Windows filesystem. (Note that forward slashes should always be 123 used as the path separator in Apache, even for Windows.) In contrast, 124 the webspace is the view of your site as delivered by the web server 125 and seen by the client. So the path <code>/dir/</code> in the 126 webspace corresponds to the path 127 <code>/usr/local/apache2/htdocs/dir/</code> in the filesystem of a 128 default Apache install on Unix. The webspace need not map directly to 129 the filesystem, since webpages may be generated dynamically 130 from databases or other locations.</p> 131 132 <h3><a name="filesystem" id="filesystem">Filesystem Containers</a></h3> 133 134 <p>The <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> 135 and <code class="directive"><a href="./mod/core.html#files"><Files></a></code> 136 directives, along with their <a class="glossarylink" href="./glossary.html#regex" title="see glossary">regex</a> 137 counterparts, apply directives to 138 parts of the filesystem. Directives enclosed in a <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> section apply to 139 the named filesystem directory and all subdirectories of that 140 directory (as well as the files in those directories). 141 The same effect can be obtained using <a href="howto/htaccess.html">.htaccess files</a>. For example, in the 142 following configuration, directory indexes will be enabled for the 143 <code>/var/web/dir1</code> directory and all subdirectories.</p> 144 145 <pre class="prettyprint lang-config"><Directory /var/web/dir1> 146 Options +Indexes 147 </Directory></pre> 148 149 150 <p>Directives enclosed in a <code class="directive"><a href="./mod/core.html#files"><Files></a></code> section apply to any file with 151 the specified name, regardless of what directory it lies in. 152 So for example, the following configuration directives will, 153 when placed in the main section of the configuration file, 154 deny access to any file named <code>private.html</code> regardless 155 of where it is found.</p> 156 157 <pre class="prettyprint lang-config"><Files private.html> 158 Order allow,deny 159 Deny from all 160 </Files></pre> 161 162 163 <p>To address files found in a particular part of the filesystem, the 164 <code class="directive"><a href="./mod/core.html#files"><Files></a></code> and 165 <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> sections 166 can be combined. For example, the following configuration will deny 167 access to <code>/var/web/dir1/private.html</code>, 168 <code>/var/web/dir1/subdir2/private.html</code>, 169 <code>/var/web/dir1/subdir3/private.html</code>, and any other instance 170 of <code>private.html</code> found under the <code>/var/web/dir1/</code> 171 directory.</p> 172 173 <pre class="prettyprint lang-config"><Directory /var/web/dir1> 174 <Files private.html> 175 Order allow,deny 176 Deny from all 177 </Files> 178 </Directory></pre> 179 180 181 182 <h3><a name="webspace" id="webspace">Webspace Containers</a></h3> 183 184 <p>The <code class="directive"><a href="./mod/core.html#location"><Location></a></code> 185 directive and its <a class="glossarylink" href="./glossary.html#regex" title="see glossary">regex</a> counterpart, on the 186 other hand, change the 187 configuration for content in the webspace. For example, the following 188 configuration prevents access to any URL-path that begins in /private. 189 In particular, it will apply to requests for 190 <code>http://yoursite.example.com/private</code>, 191 <code>http://yoursite.example.com/private123</code>, and 192 <code>http://yoursite.example.com/private/dir/file.html</code> as well 193 as any other requests starting with the <code>/private</code> string.</p> 194 195 <pre class="prettyprint lang-config"><LocationMatch ^/private> 196 Order Allow,Deny 197 Deny from all 198 </LocationMatch></pre> 199 200 201 <p>The <code class="directive"><a href="./mod/core.html#location"><Location></a></code> 202 directive need not have anything to do with the filesystem. 203 For example, the following example shows how to map a particular 204 URL to an internal Apache handler provided by <code class="module"><a href="./mod/mod_status.html">mod_status</a></code>. 205 No file called <code>server-status</code> needs to exist in the 206 filesystem.</p> 207 208 <pre class="prettyprint lang-config"><Location /server-status> 209 SetHandler server-status 210 </Location></pre> 211 212 213 214 <h3><a name="wildcards" id="wildcards">Wildcards and Regular Expressions</a></h3> 215 216 <p>The <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>, 217 <code class="directive"><a href="./mod/core.html#files"><Files></a></code>, and 218 <code class="directive"><a href="./mod/core.html#location"><Location></a></code> 219 directives can each use shell-style wildcard characters as in 220 <code>fnmatch</code> from the C standard library. The character "*" 221 matches any sequence of characters, "?" matches any single character, 222 and "[<em>seq</em>]" matches any character in <em>seq</em>. The "/" 223 character will not be matched by any wildcard; it must be specified 224 explicitly.</p> 225 226 <p>If even more flexible matching is required, each 227 container has a regular expression (regex) counterpart <code class="directive"><a href="./mod/core.html#directorymatch"><DirectoryMatch></a></code>, <code class="directive"><a href="./mod/core.html#filesmatch"><FilesMatch></a></code>, and <code class="directive"><a href="./mod/core.html#locationmatch"><LocationMatch></a></code> that allow 228 perl-compatible 229 <a class="glossarylink" href="./glossary.html#regex" title="see glossary">regular expressions</a> 230 to be used in choosing the matches. But see the section below on 231 configuration merging to find out how using regex sections will change 232 how directives are applied.</p> 233 234 <p>A non-regex wildcard section that changes the configuration of 235 all user directories could look as follows:</p> 236 237 <pre class="prettyprint lang-config"><Directory /home/*/public_html> 238 Options Indexes 239 </Directory></pre> 240 241 242 <p>Using regex sections, we can deny access to many types of image files 243 at once:</p> 244 <pre class="prettyprint lang-config"><FilesMatch \.(?i:gif|jpe?g|png)$> 245 Order allow,deny 246 Deny from all 247 </FilesMatch></pre> 248 249 250 251 252 <h3><a name="whichwhen" id="whichwhen">What to use When</a></h3> 253 254 <p>Choosing between filesystem containers and webspace containers is 255 actually quite easy. When applying directives to objects that reside 256 in the filesystem always use <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> or <code class="directive"><a href="./mod/core.html#files"><Files></a></code>. When applying directives to objects 257 that do not reside in the filesystem (such as a webpage generated from 258 a database), use <code class="directive"><a href="./mod/core.html#location"><Location></a></code>.</p> 259 260 <p>It is important to never use <code class="directive"><a href="./mod/core.html#location"><Location></a></code> when trying to restrict 261 access to objects in the filesystem. This is because many 262 different webspace locations (URLs) could map to the same filesystem 263 location, allowing your restrictions to be circumvented. 264 For example, consider the following configuration:</p> 265 266 <pre class="prettyprint lang-config"><Location /dir/> 267 Order allow,deny 268 Deny from all 269 </Location></pre> 270 271 272 <p>This works fine if the request is for 273 <code>http://yoursite.example.com/dir/</code>. But what if you are on 274 a case-insensitive filesystem? Then your restriction could be easily 275 circumvented by requesting 276 <code>http://yoursite.example.com/DIR/</code>. The <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> directive, in 277 contrast, will apply to any content served from that location, 278 regardless of how it is called. (An exception is filesystem links. 279 The same directory can be placed in more than one part of the 280 filesystem using symbolic links. The <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> directive will follow the symbolic 281 link without resetting the pathname. Therefore, for the highest level 282 of security, symbolic links should be disabled with the appropriate 283 <code class="directive"><a href="./mod/core.html#options">Options</a></code> directive.)</p> 284 285 <p>If you are, perhaps, thinking that none of this applies to you 286 because you use a case-sensitive filesystem, remember that there are 287 many other ways to map multiple webspace locations to the same 288 filesystem location. Therefore you should always use the filesystem 289 containers when you can. There is, however, one exception to this 290 rule. Putting configuration restrictions in a <code><Location 291 /></code> section is perfectly safe because this section will apply 292 to all requests regardless of the specific URL.</p> 293 294 295 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div> 296 <div class="section"> 297 <h2><a name="virtualhost" id="virtualhost">Virtual Hosts</a></h2> 298 299 <p>The <code class="directive"><a href="./mod/core.html#virtualhost"><VirtualHost></a></code> 300 container encloses directives that apply to specific hosts. 301 This is useful when serving multiple hosts from the same machine 302 with a different configuration for each. For more information, 303 see the <a href="vhosts/">Virtual Host Documentation</a>.</p> 304 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div> 305 <div class="section"> 306 <h2><a name="proxy" id="proxy">Proxy</a></h2> 307 308 <p>The <code class="directive"><a href="./mod/mod_proxy.html#proxy"><Proxy></a></code> 309 and <code class="directive"><a href="./mod/mod_proxy.html#proxymatch"><ProxyMatch></a></code> 310 containers apply enclosed configuration directives only 311 to sites accessed through <code class="module"><a href="./mod/mod_proxy.html">mod_proxy</a></code>'s proxy server 312 that match the specified URL. For example, the following configuration 313 will allow only a subset of clients to access the 314 <code>www.example.com</code> website using the proxy server:</p> 315 316 <pre class="prettyprint lang-config"><Proxy "http://www.example.com/*"> 317 Order allow,deny 318 Allow from 192.168.1.104 192.168.1.205 319 Deny from all 320 </Proxy></pre> 321 322 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div> 323 <div class="section"> 324 <h2><a name="whatwhere" id="whatwhere">What Directives are Allowed?</a></h2> 325 326 <p>To find out what directives are allowed in what types of 327 configuration sections, check the <a href="mod/directive-dict.html#Context">Context</a> of the directive. 328 Everything that is allowed in 329 <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> 330 sections is also syntactically allowed in 331 <code class="directive"><a href="./mod/core.html#directorymatch"><DirectoryMatch></a></code>, 332 <code class="directive"><a href="./mod/core.html#files"><Files></a></code>, 333 <code class="directive"><a href="./mod/core.html#filesmatch"><FilesMatch></a></code>, 334 <code class="directive"><a href="./mod/core.html#location"><Location></a></code>, 335 <code class="directive"><a href="./mod/core.html#locationmatch"><LocationMatch></a></code>, 336 <code class="directive"><a href="./mod/mod_proxy.html#proxy"><Proxy></a></code>, 337 and <code class="directive"><a href="./mod/mod_proxy.html#proxymatch"><ProxyMatch></a></code> 338 sections. There are some exceptions, however:</p> 339 340 <ul> 341 <li>The <code class="directive"><a href="./mod/core.html#allowoverride">AllowOverride</a></code> directive 342 works only in <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> 343 sections.</li> 344 345 <li>The <code>FollowSymLinks</code> and 346 <code>SymLinksIfOwnerMatch</code> <code class="directive"><a href="./mod/core.html#options">Options</a></code> work only in <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> sections or 347 <code>.htaccess</code> files.</li> 348 349 <li>The <code class="directive"><a href="./mod/core.html#options">Options</a></code> directive cannot 350 be used in <code class="directive"><a href="./mod/core.html#files"><Files></a></code> 351 and <code class="directive"><a href="./mod/core.html#filesmatch"><FilesMatch></a></code> 352 sections.</li> 353 </ul> 354 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div> 355 <div class="section"> 356 <h2><a name="mergin" id="mergin">How the sections are merged</a></h2> 357 358 <p>The configuration sections are applied in a very particular order. 359 Since this can have important effects on how configuration directives 360 are interpreted, it is important to understand how this works.</p> 361 362 <p>The order of merging is:</p> 363 364 <ol> 365 <li> <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> (except regular expressions) 366 and <code>.htaccess</code> done simultaneously (with 367 <code>.htaccess</code>, if allowed, overriding 368 <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>)</li> 369 370 <li><code class="directive"><a href="./mod/core.html#directorymatch"><DirectoryMatch></a></code> 371 (and <code><Directory ~></code>)</li> 372 373 <li><code class="directive"><a href="./mod/core.html#files"><Files></a></code> and <code class="directive"><a href="./mod/core.html#filesmatch"><FilesMatch></a></code> done 374 simultaneously</li> 375 376 <li><code class="directive"><a href="./mod/core.html#location"><Location></a></code> 377 and <code class="directive"><a href="./mod/core.html#locationmatch"><LocationMatch></a></code> done simultaneously</li> 378 </ol> 379 380 <p>Apart from <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>, each group is processed in 381 the order that they appear in the configuration files. <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> (group 1 above) 382 is processed in the order shortest directory component to longest. 383 So for example, <code><Directory /var/web/dir></code> will 384 be processed before <code><Directory 385 /var/web/dir/subdir></code>. If multiple <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> sections apply 386 to the same directory they are processed in the configuration file 387 order. Configurations included via the <code class="directive"><a href="./mod/core.html#include">Include</a></code> directive will be treated as if 388 they were inside the including file at the location of the 389 <code class="directive"><a href="./mod/core.html#include">Include</a></code> directive.</p> 390 391 <p>Sections inside <code class="directive"><a href="./mod/core.html#virtualhost"><VirtualHost></a></code> sections 392 are applied <em>after</em> the corresponding sections outside 393 the virtual host definition. This allows virtual hosts to 394 override the main server configuration.</p> 395 396 <p>When the request is served by <code class="module"><a href="./mod/mod_proxy.html">mod_proxy</a></code>, the 397 <code class="directive"><a href="./mod/mod_proxy.html#proxy"><Proxy></a></code> 398 container takes the place of the <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> container in the processing 399 order.</p> 400 401 <div class="note"><h3>Technical Note</h3> 402 There is actually a 403 <code><Location></code>/<code><LocationMatch></code> 404 sequence performed just before the name translation phase 405 (where <code>Aliases</code> and <code>DocumentRoots</code> 406 are used to map URLs to filenames). The results of this 407 sequence are completely thrown away after the translation has 408 completed. 409 </div> 410 411 <h3><a name="relationship-module-configuration" id="relationship-module-configuration">Relationship between modules and configuration sections</a></h3> 412 <p>One question that often arises after reading how configuration sections are 413 merged is related to how and when directives of specific modules like <code class="module"><a href="./mod/mod_rewrite.html">mod_rewrite</a></code> 414 are processed. The answer is not trivial and needs a bit of background. 415 Each httpd module manages its own configuration, and each of its directives in httpd.conf specify one piece 416 of configuration in a particular context. httpd does not execute a command as it is read.</p> 417 <p>At runtime, the core of httpd iterates over the defined configuration sections in the order 418 described above to determine which ones apply to the current request. When the first section matches, 419 it is considered the current configuration for this request. If a subsequent section matches too, 420 then each module with a directive in either of the sections is given a chance to merge its configuration between the two sections. The result is a third configuration, and the process goes on until all the configuration sections 421 are evaluated.</p> 422 <p>After the above step, the "real" processing of the HTTP request begins: each module has a chance to run 423 and perform whatever tasks they like. They can retrieve their own final merged configuration from the core 424 of the httpd to determine how they should act.</p> 425 <p>An example can help to visualize the whole process. The following configuration uses the 426 <code class="directive"><a href="./mod/mod_headers.html#header">Header</a></code> directive of <code class="module"><a href="./mod/mod_headers.html">mod_headers</a></code> to set 427 a specific HTTP header. What value will httpd set in the <code>CustomHeaderName</code> header for a request to 428 <code>/example/index.html</code> ? 429 </p> 430 <pre class="prettyprint lang-config"><Directory "/"> 431 Header set CustomHeaderName one 432 <FilesMatch ".*"> 433 Header set CustomHeaderName three 434 </FilesMatch> 435 </Directory> 436 437 <Directory "/example"> 438 Header set CustomHeaderName two 439 </Directory></pre> 440 441 <ul> 442 <li><code class="directive">Directory</code> "/" matches and an initial configuration to set the <code>CustomHeaderName</code> header with the value <code>one</code> is created.</li> 443 <li><code class="directive">Directory</code> "/example" matches, and since <code class="module"><a href="./mod/mod_headers.html">mod_headers</a></code> specifies in its code to override in case of a merge, a new configuration is created to set the <code>CustomHeaderName</code> header with the value <code>two</code>.</li> 444 <li><code class="directive">FilesMatch</code> ".*" matches and another merge opportunity arises, causing the <code>CustomHeaderName</code> header to be set with the value <code>three</code>.</li> 445 <li>Eventually during the next steps of the HTTP request processing <code class="module"><a href="./mod/mod_headers.html">mod_headers</a></code> will be called and it will receive the configuration to set the <code>CustomHeaderName</code> header with the value <code>three</code>. <code class="module"><a href="./mod/mod_headers.html">mod_headers</a></code> normally uses this configuration to perfom its job, namely setting the foo header. This does not mean that a module can't perform a more complex action like discarding directives because not needed or deprecated, etc..</li> 446 </ul> 447 448 <p>This is true for .htaccess too since they have the same priority as <code class="directive">Directory</code> in the merge order. The important concept to understand is that configuration sections like <code class="directive">Directory</code> and <code class="directive">FilesMatch</code> are not comparable to module specific directives like <code class="directive"><a href="./mod/mod_headers.html#header">Header</a></code> or <code class="directive"><a href="./mod/mod_rewrite.html#rewriterule">RewriteRule</a></code> because they operate on different levels. 449 </p> 450 451 452 <h3><a name="merge-examples" id="merge-examples">Some Examples</a></h3> 453 454 <p>Below is an artificial example to show the order of 455 merging. Assuming they all apply to the request, the directives in 456 this example will be applied in the order A > B > C > D > 457 E.</p> 458 459 <pre class="prettyprint lang-config"><Location "/"> 460 E 461 </Location> 462 463 <Files "f.html"> 464 D 465 </Files> 466 467 <VirtualHost *> 468 <Directory "/a/b"> 469 B 470 </Directory> 471 </VirtualHost> 472 473 <DirectoryMatch "^.*b$"> 474 C 475 </DirectoryMatch> 476 477 <Directory "/a/b"> 478 A 479 </Directory></pre> 480 481 482 <p>For a more concrete example, consider the following. Regardless of 483 any access restrictions placed in <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> sections, the <code class="directive"><a href="./mod/core.html#location"><Location></a></code> section will be 484 evaluated last and will allow unrestricted access to the server. In 485 other words, order of merging is important, so be careful!</p> 486 487 <pre class="prettyprint lang-config"><Location "/"> 488 Require all granted 489 </Location> 490 491 # Woops! This <Directory> section will have no effect 492 <Directory "/"> 493 <RequireAll> 494 Require all granted 495 Require not host badguy.example.com 496 </RequireAll> 497 </Directory></pre> 498 499 500 501 502 </div></div> 503 <div class="bottomlang"> 504 <p><span>Available Languages: </span><a href="./en/sections.html" title="English"> en </a> | 505 <a href="./fr/sections.html" hreflang="fr" rel="alternate" title="Français"> fr </a> | 506 <a href="./ja/sections.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> | 507 <a href="./ko/sections.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> | 508 <a href="./tr/sections.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p> 509 </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> 510 <script type="text/javascript"><!--//--><![CDATA[//><!-- 511 var comments_shortname = 'httpd'; 512 var comments_identifier = 'http://httpd.apache.org/docs/2.2/sections.html'; 513 (function(w, d) { 514 if (w.location.hostname.toLowerCase() == "httpd.apache.org") { 515 d.write('<div id="comments_thread"><\/div>'); 516 var s = d.createElement('script'); 517 s.type = 'text/javascript'; 518 s.async = true; 519 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; 520 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); 521 } 522 else { 523 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); 524 } 525 })(window, document); 526 //--><!]]></script></div><div id="footer"> 527 <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> 528 <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[//><!-- 529 if (typeof(prettyPrint) !== 'undefined') { 530 prettyPrint(); 531 } 532 //--><!]]></script> 533 </body></html>