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