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" />
6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7 This file is generated from xml source: DO NOT EDIT
8 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
10 <title>Configuration Sections - Apache HTTP Server Version 2.5</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">
17 <link href="./images/favicon.ico" rel="shortcut icon" /></head>
18 <body id="manual-page"><div id="page-header">
19 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/quickreference.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.5</p>
21 <img alt="" src="./images/feather.png" /></div>
22 <div class="up"><a href="./"><img title="<-" alt="<-" src="./images/left.gif" /></a></div>
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.5</a></div><div id="page-content"><div id="preamble"><h1>Configuration Sections</h1>
26 <p><span>Available Languages: </span><a href="./en/sections.html" title="English"> en </a> |
27 <a href="./fr/sections.html" hreflang="fr" rel="alternate" title="Français"> fr </a> |
28 <a href="./ja/sections.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
29 <a href="./ko/sections.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
30 <a href="./tr/sections.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
32 <p>Directives in the <a href="configuring.html">configuration files</a> may apply to the
33 entire server, or they may be restricted to apply only to particular
34 directories, files, hosts, or URLs. This document describes how to
35 use configuration section containers or <code>.htaccess</code> files
36 to change the scope of other configuration directives.</p>
38 <div id="quickview"><ul id="toc"><li><img alt="" src="./images/down.gif" /> <a href="#types">Types of Configuration Section Containers</a></li>
39 <li><img alt="" src="./images/down.gif" /> <a href="#file-and-web">Filesystem, Webspace, and Boolean Expressions</a></li>
40 <li><img alt="" src="./images/down.gif" /> <a href="#virtualhost">Virtual Hosts</a></li>
41 <li><img alt="" src="./images/down.gif" /> <a href="#proxy">Proxy</a></li>
42 <li><img alt="" src="./images/down.gif" /> <a href="#whatwhere">What Directives are Allowed?</a></li>
43 <li><img alt="" src="./images/down.gif" /> <a href="#merging">How the sections are merged</a></li>
44 </ul><h3>See also</h3><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div>
45 <div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
47 <h2><a name="types" id="types">Types of Configuration Section Containers</a> <a title="Permanent link" href="#types" class="permalink">¶</a></h2>
49 <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#if"><If></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_md.html#mdomainsetsection"><MDomainSet></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>
51 <p>There are two basic types of containers. Most containers are
52 evaluated for each request. The enclosed directives are applied only
53 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
54 <code class="directive"><a href="./mod/mod_version.html#ifversion"><IfVersion></a></code>
55 containers, on the other hand, are evaluated only at server startup
56 and restart. If their conditions are true at startup, then the
57 enclosed directives will apply to all requests. If the conditions are
58 not true, the enclosed directives will be ignored.</p>
60 <p>The <code class="directive"><a href="./mod/core.html#ifdefine"><IfDefine></a></code> directive
61 encloses directives that will only be applied if an appropriate
62 parameter is defined on the <code class="program"><a href="./programs/httpd.html">httpd</a></code> command line. For example,
63 with the following configuration, all requests will be redirected
64 to another site only if the server is started using
65 <code>httpd -DClosedForNow</code>:</p>
67 <pre class="prettyprint lang-config"><IfDefine ClosedForNow>
68 Redirect "/" "http://otherserver.example.com/"
69 </IfDefine></pre>
72 <p>The <code class="directive"><a href="./mod/core.html#ifmodule"><IfModule></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>
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>
86 <pre class="prettyprint lang-config"><IfModule mod_mime_magic.c>
87 MimeMagicFile "conf/magic"
88 </IfModule></pre>
91 <p>The <code class="directive"><a href="./mod/mod_version.html#ifversion"><IfVersion></a></code>
92 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
93 only be applied if a particular version of the server is executing. This
94 module is designed for the use in test suites and large networks which have to
95 deal with different httpd versions and different configurations.</p>
97 <pre class="prettyprint lang-config"><IfVersion >= 2.4>
98 # this happens only in versions greater or
100 </IfVersion></pre>
103 <p><code class="directive"><a href="./mod/core.html#ifdefine"><IfDefine></a></code>,
104 <code class="directive"><a href="./mod/core.html#ifmodule"><IfModule></a></code>, and the
105 <code class="directive"><a href="./mod/mod_version.html#ifversion"><IfVersion></a></code>
106 can apply negative conditions by preceding their test with "!".
107 Also, these sections can be nested to achieve more complex
109 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
110 <div class="section">
111 <h2><a name="file-and-web" id="file-and-web">Filesystem, Webspace, and Boolean Expressions</a> <a title="Permanent link" href="#file-and-web" class="permalink">¶</a></h2>
113 <p>The most commonly used configuration section containers are the
114 ones that change the configuration of particular places in the
115 filesystem or webspace. First, it is important to understand the
116 difference between the two. The filesystem is the view of your disks
117 as seen by your operating system. For example, in a default install,
118 Apache httpd resides at <code>/usr/local/apache2</code> in the Unix
119 filesystem or <code>"c:/Program Files/Apache Group/Apache2"</code> in
120 the Windows filesystem. (Note that forward slashes should always be
121 used as the path separator in Apache httpd configuration files, even for Windows.) In contrast,
122 the webspace is the view of your site as delivered by the web server
123 and seen by the client. So the path <code>/dir/</code> in the
124 webspace corresponds to the path
125 <code>/usr/local/apache2/htdocs/dir/</code> in the filesystem of a
126 default Apache httpd install on Unix. The webspace need not map directly to
127 the filesystem, since webpages may be generated dynamically
128 from databases or other locations.</p>
130 <h3><a name="filesystem" id="filesystem">Filesystem Containers</a></h3>
132 <p>The <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>
133 and <code class="directive"><a href="./mod/core.html#files"><Files></a></code>
134 directives, along with their <a class="glossarylink" href="./glossary.html#regex" title="see glossary">regex</a>
135 counterparts, apply directives to
136 parts of the filesystem. Directives enclosed in a <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> section apply to
137 the named filesystem directory and all subdirectories of that
138 directory (as well as the files in those directories).
139 The same effect can be obtained using <a href="howto/htaccess.html">.htaccess files</a>. For example, in the
140 following configuration, directory indexes will be enabled for the
141 <code>/var/web/dir1</code> directory and all subdirectories.</p>
143 <pre class="prettyprint lang-config"><Directory "/var/web/dir1">
145 </Directory></pre>
148 <p>Directives enclosed in a <code class="directive"><a href="./mod/core.html#files"><Files></a></code> section apply to any file with
149 the specified name, regardless of what directory it lies in.
150 So for example, the following configuration directives will,
151 when placed in the main section of the configuration file,
152 deny access to any file named <code>private.html</code> regardless
153 of where it is found.</p>
155 <pre class="prettyprint lang-config"><Files "private.html">
160 <p>To address files found in a particular part of the filesystem, the
161 <code class="directive"><a href="./mod/core.html#files"><Files></a></code> and
162 <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> sections
163 can be combined. For example, the following configuration will deny
164 access to <code>/var/web/dir1/private.html</code>,
165 <code>/var/web/dir1/subdir2/private.html</code>,
166 <code>/var/web/dir1/subdir3/private.html</code>, and any other instance
167 of <code>private.html</code> found under the <code>/var/web/dir1/</code>
170 <pre class="prettyprint lang-config"><Directory "/var/web/dir1">
171 <Files "private.html">
174 </Directory></pre>
178 <h3><a name="webspace" id="webspace">Webspace Containers</a></h3>
180 <p>The <code class="directive"><a href="./mod/core.html#location"><Location></a></code>
181 directive and its <a class="glossarylink" href="./glossary.html#regex" title="see glossary">regex</a> counterpart, on
182 the other hand, change the
183 configuration for content in the webspace. For example, the following
184 configuration prevents access to any URL-path that begins in /private.
185 In particular, it will apply to requests for
186 <code>http://yoursite.example.com/private</code>,
187 <code>http://yoursite.example.com/private123</code>, and
188 <code>http://yoursite.example.com/private/dir/file.html</code> as well
189 as any other requests starting with the <code>/private</code> string.</p>
191 <pre class="prettyprint lang-config"><LocationMatch "^/private">
193 </LocationMatch></pre>
196 <p>The <code class="directive"><a href="./mod/core.html#location"><Location></a></code>
197 directive need not have anything to do with the filesystem.
198 For example, the following example shows how to map a particular
199 URL to an internal Apache HTTP Server handler provided by <code class="module"><a href="./mod/mod_status.html">mod_status</a></code>.
200 No file called <code>server-status</code> needs to exist in the
203 <pre class="prettyprint lang-config"><Location "/server-status">
204 SetHandler server-status
205 </Location></pre>
209 <h3><a name="overlapping-webspace" id="overlapping-webspace">Overlapping Webspace</a></h3>
210 <p>In order to have two overlapping URLs one has to consider the order in which
211 certain sections or directives are evaluated. For
212 <code class="directive"><a href="./mod/core.html#location"><Location></a></code> this would be:</p>
213 <pre class="prettyprint lang-config"><Location "/foo">
215 <Location "/foo/bar">
216 </Location></pre>
218 <p><code class="directive"><a href="./mod/mod_alias.html#alias"><Alias></a></code>es on the other hand,
219 are mapped vice-versa:</p>
220 <pre class="prettyprint lang-config">Alias "/foo/bar" "/srv/www/uncommon/bar"
221 Alias "/foo" "/srv/www/common/foo"</pre>
223 <p>The same is true for the <code class="directive"><a href="./mod/mod_proxy.html#proxypass">ProxyPass</a></code>
225 <pre class="prettyprint lang-config">ProxyPass "/special-area" "http://special.example.com" smax=5 max=10
226 ProxyPass "/" "balancer://mycluster/" stickysession=JSESSIONID|jsessionid nofailover=On</pre>
230 <h3><a name="wildcards" id="wildcards">Wildcards and Regular Expressions</a></h3>
232 <p>The <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>,
233 <code class="directive"><a href="./mod/core.html#files"><Files></a></code>, and
234 <code class="directive"><a href="./mod/core.html#location"><Location></a></code>
235 directives can each use shell-style wildcard characters as in
236 <code>fnmatch</code> from the C standard library. The character "*"
237 matches any sequence of characters, "?" matches any single character,
238 and "[<em>seq</em>]" matches any character in <em>seq</em>. The "/"
239 character will not be matched by any wildcard; it must be specified
242 <p>If even more flexible matching is required, each
243 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
245 <a class="glossarylink" href="./glossary.html#regex" title="see glossary">regular expressions</a>
246 to be used in choosing the matches. But see the section below on
247 configuration merging to find out how using regex sections will change
248 how directives are applied.</p>
250 <p>A non-regex wildcard section that changes the configuration of
251 all user directories could look as follows:</p>
253 <pre class="prettyprint lang-config"><Directory "/home/*/public_html">
255 </Directory></pre>
258 <p>Using regex sections, we can deny access to many types of image files
260 <pre class="prettyprint lang-config"><FilesMatch "\.(?i:gif|jpe?g|png)$">
262 </FilesMatch></pre>
265 <p>Regular expressions containing <strong>named groups and
266 backreferences</strong> are added to the environment with the
267 corresponding name in uppercase. This allows elements of filename paths
268 and URLs to be referenced from within <a href="expr.html">expressions</a>
269 and modules like <code class="module"><a href="./mod/mod_rewrite.html">mod_rewrite</a></code>.</p>
271 <pre class="prettyprint lang-config"><DirectoryMatch "^/var/www/combined/(?<SITENAME>[^/]+)">
272 require ldap-group "cn=%{env:MATCH_SITENAME},ou=combined,o=Example"
273 </DirectoryMatch></pre>
278 <h3><a name="expressions" id="expressions">Boolean expressions</a></h3>
279 <p>The <code class="directive"><a href="./mod/core.html#if"><If></a></code>
280 directive change the configuration depending on a condition which can be
281 expressed by a boolean expression. For example, the following configuration
282 denies access if the HTTP Referer header does not start with
283 "http://www.example.com/".</p>
284 <pre class="prettyprint lang-config"><If "!(%{HTTP_REFERER} -strmatch 'http://www.example.com/*')">
291 <h3><a name="whichwhen" id="whichwhen">What to use When</a></h3>
293 <p>Choosing between filesystem containers and webspace containers is
294 actually quite easy. When applying directives to objects that reside
295 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
296 that do not reside in the filesystem (such as a webpage generated from
297 a database), use <code class="directive"><a href="./mod/core.html#location"><Location></a></code>.</p>
299 <p>It is important to never use <code class="directive"><a href="./mod/core.html#location"><Location></a></code> when trying to restrict
300 access to objects in the filesystem. This is because many
301 different webspace locations (URLs) could map to the same filesystem
302 location, allowing your restrictions to be circumvented.
303 For example, consider the following configuration:</p>
305 <pre class="prettyprint lang-config"><Location "/dir/">
307 </Location></pre>
310 <p>This works fine if the request is for
311 <code>http://yoursite.example.com/dir/</code>. But what if you are on
312 a case-insensitive filesystem? Then your restriction could be easily
313 circumvented by requesting
314 <code>http://yoursite.example.com/DIR/</code>. The <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> directive, in
315 contrast, will apply to any content served from that location,
316 regardless of how it is called. (An exception is filesystem links.
317 The same directory can be placed in more than one part of the
318 filesystem using symbolic links. The <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> directive will follow the symbolic
319 link without resetting the pathname. Therefore, for the highest level
320 of security, symbolic links should be disabled with the appropriate
321 <code class="directive"><a href="./mod/core.html#options">Options</a></code> directive.)</p>
323 <p>If you are, perhaps, thinking that none of this applies to you
324 because you use a case-sensitive filesystem, remember that there are
325 many other ways to map multiple webspace locations to the same
326 filesystem location. Therefore you should always use the filesystem
327 containers when you can. There is, however, one exception to this
328 rule. Putting configuration restrictions in a <code><Location
329 "/"></code> section is perfectly safe because this section will apply
330 to all requests regardless of the specific URL.</p>
333 <h3><a name="nesting" id="nesting">Nesting of sections</a></h3>
335 <p>Some section types can be nested inside other section types. On the one
336 hand, <code class="directive"><a href="./mod/core.html#files"><Files></a></code> can be used
337 inside <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>. On
338 the other hand, <code class="directive"><a href="./mod/core.html#if"><If></a></code> can
339 be used inside <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>,
340 <code class="directive"><a href="./mod/core.html#location"><Location></a></code>, and <code class="directive"><a href="./mod/core.html#files"><Files></a></code> sections (but not inside another
341 <code class="directive"><a href="./mod/core.html#if"><If></a></code>). The regex
342 counterparts of the named section behave identically.</p>
344 <p>Nested sections are merged after non-nested sections of the same type.</p>
348 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
349 <div class="section">
350 <h2><a name="virtualhost" id="virtualhost">Virtual Hosts</a> <a title="Permanent link" href="#virtualhost" class="permalink">¶</a></h2>
352 <p>The <code class="directive"><a href="./mod/core.html#virtualhost"><VirtualHost></a></code>
353 container encloses directives that apply to specific hosts.
354 This is useful when serving multiple hosts from the same machine
355 with a different configuration for each. For more information,
356 see the <a href="vhosts/">Virtual Host Documentation</a>.</p>
357 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
358 <div class="section">
359 <h2><a name="proxy" id="proxy">Proxy</a> <a title="Permanent link" href="#proxy" class="permalink">¶</a></h2>
361 <p>The <code class="directive"><a href="./mod/mod_proxy.html#proxy"><Proxy></a></code>
362 and <code class="directive"><a href="./mod/mod_proxy.html#proxymatch"><ProxyMatch></a></code>
363 containers apply enclosed configuration directives only
364 to sites accessed through <code class="module"><a href="./mod/mod_proxy.html">mod_proxy</a></code>'s proxy server
365 that match the specified URL. For example, the following configuration
366 will allow only a subset of clients to access the
367 <code>www.example.com</code> website using the proxy server:</p>
369 <pre class="prettyprint lang-config"><Proxy "http://www.example.com/*">
370 Require host yournetwork.example.com
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="whatwhere" id="whatwhere">What Directives are Allowed?</a> <a title="Permanent link" href="#whatwhere" class="permalink">¶</a></h2>
377 <p>To find out what directives are allowed in what types of
378 configuration sections, check the <a href="mod/directive-dict.html#Context">Context</a> of the directive.
379 Everything that is allowed in
380 <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>
381 sections is also syntactically allowed in
382 <code class="directive"><a href="./mod/core.html#directorymatch"><DirectoryMatch></a></code>,
383 <code class="directive"><a href="./mod/core.html#files"><Files></a></code>,
384 <code class="directive"><a href="./mod/core.html#filesmatch"><FilesMatch></a></code>,
385 <code class="directive"><a href="./mod/core.html#location"><Location></a></code>,
386 <code class="directive"><a href="./mod/core.html#locationmatch"><LocationMatch></a></code>,
387 <code class="directive"><a href="./mod/mod_proxy.html#proxy"><Proxy></a></code>,
388 and <code class="directive"><a href="./mod/mod_proxy.html#proxymatch"><ProxyMatch></a></code>
389 sections. There are some exceptions, however:</p>
392 <li>The <code class="directive"><a href="./mod/core.html#allowoverride">AllowOverride</a></code> directive
393 works only in <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>
396 <li>The <code>FollowSymLinks</code> and
397 <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
398 <code>.htaccess</code> files.</li>
400 <li>The <code class="directive"><a href="./mod/core.html#options">Options</a></code> directive cannot
401 be used in <code class="directive"><a href="./mod/core.html#files"><Files></a></code>
402 and <code class="directive"><a href="./mod/core.html#filesmatch"><FilesMatch></a></code>
405 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
406 <div class="section">
407 <h2><a name="merging" id="merging">How the sections are merged</a> <a title="Permanent link" href="#merging" class="permalink">¶</a></h2>
409 <p>The configuration sections are applied in a very particular order.
410 Since this can have important effects on how configuration directives
411 are interpreted, it is important to understand how this works.</p>
413 <p>The order of merging is:</p>
416 <li> <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> (except regular expressions)
417 and <code>.htaccess</code> done simultaneously (with
418 <code>.htaccess</code>, if allowed, overriding
419 <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>)</li>
421 <li><code class="directive"><a href="./mod/core.html#directorymatch"><DirectoryMatch></a></code>
422 (and <code><Directory "~"></code>)</li>
424 <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
427 <li><code class="directive"><a href="./mod/core.html#location"><Location></a></code>
428 and <code class="directive"><a href="./mod/core.html#locationmatch"><LocationMatch></a></code> done simultaneously</li>
430 <li><code class="directive"><a href="./mod/core.html#if"><If></a></code>
435 <p>Some important remarks:</p>
437 <li>Apart from <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>, within each group the sections are
438 processed in the order they appear in the configuration files.
439 For example, a request for <em>/foo/bar</em> will match
440 <code><Location "/foo/bar"></code> and
441 <code><Location "/foo"></code> (group 4 in this case):
442 both sections will be evaluated
443 but in the order they appear in the configuration files.</li>
444 <li><code class="directive"><a href="./mod/core.html#directory"><Directory></a></code>
445 (group 1 above) is processed in the order shortest directory
446 component to longest. For example,
447 <code><Directory "/var/web/dir"></code> will be processed before
448 <code><Directory "/var/web/dir/subdir"></code>.</li>
449 <li>If multiple <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> sections apply
450 to the same directory they are processed in the configuration file
452 <li>Configurations included via the <code class="directive"><a href="./mod/core.html#include">Include</a></code> directive will be treated as if
453 they were inside the including file at the location of the
454 <code class="directive"><a href="./mod/core.html#include">Include</a></code> directive.</li>
455 <li>Sections inside <code class="directive"><a href="./mod/core.html#virtualhost"><VirtualHost></a></code> sections
456 are applied <em>after</em> the corresponding sections outside
457 the virtual host definition. This allows virtual hosts to
458 override the main server configuration.</li>
459 <li>When the request is served by <code class="module"><a href="./mod/mod_proxy.html">mod_proxy</a></code>, the
460 <code class="directive"><a href="./mod/mod_proxy.html#proxy"><Proxy></a></code>
461 container takes the place of the <code class="directive"><a href="./mod/core.html#directory"><Directory></a></code> container in the processing
465 <div class="note"><h3>Technical Note</h3>
467 <code><Location></code>/<code><LocationMatch></code>
468 sequence performed just before the name translation phase
469 (where <code>Aliases</code> and <code>DocumentRoots</code>
470 are used to map URLs to filenames). The results of this
471 sequence are completely thrown away after the translation has
475 <h3><a name="relationship-module-configuration" id="relationship-module-configuration">Relationship between modules and configuration sections</a></h3>
476 <p>One question that often arises after reading how configuration sections are
477 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>
478 are processed. The answer is not trivial and needs a bit of background.
479 Each httpd module manages its own configuration, and each of its directives in httpd.conf specify one piece
480 of configuration in a particular context. httpd does not execute a command as it is read.</p>
481 <p>At runtime, the core of httpd iterates over the defined configuration sections in the order
482 described above to determine which ones apply to the current request. When the first section matches,
483 it is considered the current configuration for this request. If a subsequent section matches too,
484 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
486 <p>After the above step, the "real" processing of the HTTP request begins: each module has a chance to run
487 and perform whatever tasks they like. They can retrieve their own final merged configuration from the core
488 of the httpd to determine how they should act.</p>
489 <p>An example can help to visualize the whole process. The following configuration uses the
490 <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
491 a specific HTTP header. What value will httpd set in the <code>CustomHeaderName</code> header for a request to
492 <code>/example/index.html</code> ?
494 <pre class="prettyprint lang-config"><Directory "/">
495 Header set CustomHeaderName one
496 <FilesMatch ".*">
497 Header set CustomHeaderName three
501 <Directory "/example">
502 Header set CustomHeaderName two
503 </Directory></pre>
506 <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>
507 <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>
508 <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>
509 <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>
512 <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.
516 <h3><a name="merge-examples" id="merge-examples">Some useful examples</a></h3>
518 <p>Below is an artificial example to show the order of
519 merging. Assuming they all apply to the request, the directives in
520 this example will be applied in the order A > B > C > D >
523 <pre class="prettyprint lang-config"><Location "/">
527 <Files "f.html">
531 <VirtualHost *>
532 <Directory "/a/">
537 <DirectoryMatch "^.*b$">
539 </DirectoryMatch>
541 <Directory "/a/b">
543 </Directory></pre>
547 <p>For a more concrete example, consider the following. Regardless of
548 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
549 evaluated last and will allow unrestricted access to the server. In
550 other words, order of merging is important, so be careful!</p>
552 <pre class="prettyprint lang-config"><Location "/">
556 # Whoops! This <Directory> section will have no effect
557 <Directory "/">
560 Require not host badguy.example.com
562 </Directory></pre>
568 <div class="bottomlang">
569 <p><span>Available Languages: </span><a href="./en/sections.html" title="English"> en </a> |
570 <a href="./fr/sections.html" hreflang="fr" rel="alternate" title="Français"> fr </a> |
571 <a href="./ja/sections.html" hreflang="ja" rel="alternate" title="Japanese"> ja </a> |
572 <a href="./ko/sections.html" hreflang="ko" rel="alternate" title="Korean"> ko </a> |
573 <a href="./tr/sections.html" hreflang="tr" rel="alternate" title="Türkçe"> tr </a></p>
574 </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>
575 <script type="text/javascript"><!--//--><![CDATA[//><!--
576 var comments_shortname = 'httpd';
577 var comments_identifier = 'http://httpd.apache.org/docs/trunk/sections.html';
579 if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
580 d.write('<div id="comments_thread"><\/div>');
581 var s = d.createElement('script');
582 s.type = 'text/javascript';
584 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
585 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
588 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
590 })(window, document);
591 //--><!]]></script></div><div id="footer">
592 <p class="apache">Copyright 2019 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>
593 <p class="menu"><a href="./mod/">Modules</a> | <a href="./mod/quickreference.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[//><!--
594 if (typeof(prettyPrint) !== 'undefined') {