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