]> granicus.if.org Git - apache/blob - docs/manual/sections.html.en
Update 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 <meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
5 <!--
6         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7               This file is generated from xml source: DO NOT EDIT
8         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
9       -->
10 <title>Configuration Sections - Apache HTTP Server Version 2.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">
15 </script>
16
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.gif" /></div>
22 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="./images/left.gif" /></a></div>
23 <div id="path">
24 <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>
25 <div class="toplang">
26 <p><span>Available Languages: </span><a href="./en/sections.html" title="English">&nbsp;en&nbsp;</a> |
27 <a href="./fr/sections.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
28 <a href="./ja/sections.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
29 <a href="./ko/sections.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
30 <a href="./tr/sections.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
31 </div>
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>
37 </div>
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><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>
46 <div class="section">
47 <h2><a name="types" id="types">Types of Configuration Section Containers</a></h2>
48
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">&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>
50
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">&lt;IfDefine&gt;</a></code>, <code class="directive"><a href="./mod/core.html#ifmodule">&lt;IfModule&gt;</a></code>, and
54 <code class="directive"><a href="./mod/mod_version.html#ifversion">&lt;IfVersion&gt;</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>
59
60 <p>The <code class="directive"><a href="./mod/core.html#ifdefine">&lt;IfDefine&gt;</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>
66
67 <pre class="prettyprint lang-config">&lt;IfDefine ClosedForNow&gt;
68     Redirect "/" "http://otherserver.example.com/"
69 &lt;/IfDefine&gt;</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">&lt;IfModule mod_mime_magic.c&gt;
87     MimeMagicFile conf/magic
88 &lt;/IfModule&gt;</pre>
89
90
91 <p>The <code class="directive"><a href="./mod/mod_version.html#ifversion">&lt;IfVersion&gt;</a></code>
92 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
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>
96
97 <pre class="prettyprint lang-config">&lt;IfVersion &gt;= 2.4&gt;
98     # this happens only in versions greater or
99     # equal 2.4.0.
100 &lt;/IfVersion&gt;</pre>
101
102
103 <p><code class="directive"><a href="./mod/core.html#ifdefine">&lt;IfDefine&gt;</a></code>,
104 <code class="directive"><a href="./mod/core.html#ifmodule">&lt;IfModule&gt;</a></code>, and the
105 <code class="directive"><a href="./mod/mod_version.html#ifversion">&lt;IfVersion&gt;</a></code>
106 can apply negative conditions by preceding their test with "!".
107 Also, these sections can be nested to achieve more complex
108 restrictions.</p>
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></h2>
112
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>
129
130 <h3><a name="filesystem" id="filesystem">Filesystem Containers</a></h3>
131
132 <p>The <code class="directive"><a href="./mod/core.html#directory">&lt;Directory&gt;</a></code>
133 and <code class="directive"><a href="./mod/core.html#files">&lt;Files&gt;</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">&lt;Directory&gt;</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>
142
143 <pre class="prettyprint lang-config">&lt;Directory "/var/web/dir1"&gt;
144     Options +Indexes
145 &lt;/Directory&gt;</pre>
146
147
148 <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
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>
154
155 <pre class="prettyprint lang-config">&lt;Files "private.html"&gt;
156     Require all denied
157 &lt;/Files&gt;</pre>
158
159
160 <p>To address files found in a particular part of the filesystem, the
161 <code class="directive"><a href="./mod/core.html#files">&lt;Files&gt;</a></code> and
162 <code class="directive"><a href="./mod/core.html#directory">&lt;Directory&gt;</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>
168 directory.</p>
169
170 <pre class="prettyprint lang-config">&lt;Directory "/var/web/dir1"&gt;
171     &lt;Files "private.html"&gt;
172         Require all denied
173     &lt;/Files&gt;
174 &lt;/Directory&gt;</pre>
175
176
177
178 <h3><a name="webspace" id="webspace">Webspace Containers</a></h3>
179
180 <p>The <code class="directive"><a href="./mod/core.html#location">&lt;Location&gt;</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>
190
191 <pre class="prettyprint lang-config">&lt;LocationMatch "^/private"&gt;
192     Require all denied
193 &lt;/LocationMatch&gt;</pre>
194
195
196 <p>The <code class="directive"><a href="./mod/core.html#location">&lt;Location&gt;</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
201 filesystem.</p>
202
203 <pre class="prettyprint lang-config">&lt;Location "/server-status"&gt;
204     SetHandler server-status
205 &lt;/Location&gt;</pre>
206
207
208
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">&lt;Location&gt;</a></code> this would be:</p>
213 <pre class="prettyprint lang-config">&lt;Location "/foo"&gt;
214 &lt;/Location&gt;
215 &lt;Location "/foo/bar"&gt;
216 &lt;/Location&gt;</pre>
217
218 <p><code class="directive"><a href="./mod/mod_alias.html#alias">&lt;Alias&gt;</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>
222
223 <p>The same is true for the <code class="directive"><a href="./mod/mod_proxy.html#proxypass">ProxyPass</a></code>
224 directives:</p>
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>
227
228
229
230 <h3><a name="wildcards" id="wildcards">Wildcards and Regular Expressions</a></h3>
231
232 <p>The <code class="directive"><a href="./mod/core.html#directory">&lt;Directory&gt;</a></code>,
233 <code class="directive"><a href="./mod/core.html#files">&lt;Files&gt;</a></code>, and
234 <code class="directive"><a href="./mod/core.html#location">&lt;Location&gt;</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
240 explicitly.</p>
241
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">&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
244 perl-compatible
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>
249
250 <p>A non-regex wildcard section that changes the configuration of
251 all user directories could look as follows:</p>
252
253 <pre class="prettyprint lang-config">&lt;Directory "/home/*/public_html"&gt;
254     Options Indexes
255 &lt;/Directory&gt;</pre>
256
257
258 <p>Using regex sections, we can deny access to many types of image files
259 at once:</p>
260 <pre class="prettyprint lang-config">&lt;FilesMatch "\.(?i:gif|jpe?g|png)$"&gt;
261     Require all denied
262 &lt;/FilesMatch&gt;</pre>
263
264
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>
270
271 <pre class="prettyprint lang-config">&lt;DirectoryMatch "^/var/www/combined/(?&lt;SITENAME&gt;[^/]+)"&gt;
272     require ldap-group cn=%{env:MATCH_SITENAME},ou=combined,o=Example
273 &lt;/DirectoryMatch&gt;</pre>
274
275
276
277
278 <h3><a name="expressions" id="expressions">Boolean expressions</a></h3>
279 <p>The <code class="directive"><a href="./mod/core.html#if">&lt;If&gt;</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">&lt;If "!(%{HTTP_REFERER} -strmatch 'http://www.example.com/*')"&gt;
285     Require all denied
286 &lt;/If&gt;</pre>
287
288
289
290
291 <h3><a name="whichwhen" id="whichwhen">What to use When</a></h3>
292
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">&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
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">&lt;Location&gt;</a></code>.</p>
298
299 <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
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>
304
305 <pre class="prettyprint lang-config">&lt;Location "/dir/"&gt;
306     Require all denied
307 &lt;/Location&gt;</pre>
308
309
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">&lt;Directory&gt;</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">&lt;Directory&gt;</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>
322
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>&lt;Location
329 "/"&gt;</code> section is perfectly safe because this section will apply
330 to all requests regardless of the specific URL.</p>
331
332
333 <h3><a name="nesting" id="nesting">Nesting of sections</a></h3>
334
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">&lt;Files&gt;</a></code> can be used
337 inside <code class="directive"><a href="./mod/core.html#directory">&lt;Directory&gt;</a></code>.  On
338 the other hand, <code class="directive"><a href="./mod/core.html#if">&lt;If&gt;</a></code> can
339 be used inside <code class="directive"><a href="./mod/core.html#directory">&lt;Directory&gt;</a></code>,
340 <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
341 counterparts of the named section behave identically.</p>
342
343 <p>Nested sections are merged after non-nested sections of the same type.</p>
344
345
346
347 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
348 <div class="section">
349 <h2><a name="virtualhost" id="virtualhost">Virtual Hosts</a></h2>
350
351 <p>The <code class="directive"><a href="./mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code>
352 container encloses directives that apply to specific hosts.
353 This is useful when serving multiple hosts from the same machine
354 with a different configuration for each.  For more information,
355 see the <a href="vhosts/">Virtual Host Documentation</a>.</p>
356 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
357 <div class="section">
358 <h2><a name="proxy" id="proxy">Proxy</a></h2>
359
360 <p>The <code class="directive"><a href="./mod/mod_proxy.html#proxy">&lt;Proxy&gt;</a></code>
361 and <code class="directive"><a href="./mod/mod_proxy.html#proxymatch">&lt;ProxyMatch&gt;</a></code>
362 containers apply enclosed configuration directives only
363 to sites accessed through <code class="module"><a href="./mod/mod_proxy.html">mod_proxy</a></code>'s proxy server
364 that match the specified URL.  For example, the following configuration
365 will prevent the proxy server from being used to access the
366 <code>www.example.com</code> website.</p>
367
368 <pre class="prettyprint lang-config">&lt;Proxy http://www.example.com/*&gt;
369     Require all granted
370 &lt;/Proxy&gt;</pre>
371
372 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
373 <div class="section">
374 <h2><a name="whatwhere" id="whatwhere">What Directives are Allowed?</a></h2>
375
376 <p>To find out what directives are allowed in what types of
377 configuration sections, check the <a href="mod/directive-dict.html#Context">Context</a> of the directive.
378 Everything that is allowed in
379 <code class="directive"><a href="./mod/core.html#directory">&lt;Directory&gt;</a></code>
380 sections is also syntactically allowed in
381 <code class="directive"><a href="./mod/core.html#directorymatch">&lt;DirectoryMatch&gt;</a></code>,
382 <code class="directive"><a href="./mod/core.html#files">&lt;Files&gt;</a></code>,
383 <code class="directive"><a href="./mod/core.html#filesmatch">&lt;FilesMatch&gt;</a></code>,
384 <code class="directive"><a href="./mod/core.html#location">&lt;Location&gt;</a></code>,
385 <code class="directive"><a href="./mod/core.html#locationmatch">&lt;LocationMatch&gt;</a></code>,
386 <code class="directive"><a href="./mod/mod_proxy.html#proxy">&lt;Proxy&gt;</a></code>,
387 and <code class="directive"><a href="./mod/mod_proxy.html#proxymatch">&lt;ProxyMatch&gt;</a></code>
388 sections.  There are some exceptions, however:</p>
389
390 <ul>
391 <li>The <code class="directive"><a href="./mod/core.html#allowoverride">AllowOverride</a></code> directive
392 works only in <code class="directive"><a href="./mod/core.html#directory">&lt;Directory&gt;</a></code>
393 sections.</li>
394
395 <li>The <code>FollowSymLinks</code> and
396 <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
397 <code>.htaccess</code> files.</li>
398
399 <li>The <code class="directive"><a href="./mod/core.html#options">Options</a></code> directive cannot
400 be used in <code class="directive"><a href="./mod/core.html#files">&lt;Files&gt;</a></code>
401 and <code class="directive"><a href="./mod/core.html#filesmatch">&lt;FilesMatch&gt;</a></code>
402 sections.</li>
403 </ul>
404 </div><div class="top"><a href="#page-header"><img alt="top" src="./images/up.gif" /></a></div>
405 <div class="section">
406 <h2><a name="merging" id="merging">How the sections are merged</a></h2>
407
408 <p>The configuration sections are applied in a very particular order.
409 Since this can have important effects on how configuration directives
410 are interpreted, it is important to understand how this works.</p>
411
412     <p>The order of merging is:</p>
413
414     <ol>
415       <li> <code class="directive"><a href="./mod/core.html#directory">&lt;Directory&gt;</a></code> (except regular expressions)
416       and <code>.htaccess</code> done simultaneously (with
417       <code>.htaccess</code>, if allowed, overriding
418       <code class="directive"><a href="./mod/core.html#directory">&lt;Directory&gt;</a></code>)</li>
419
420       <li><code class="directive"><a href="./mod/core.html#directorymatch">&lt;DirectoryMatch&gt;</a></code>
421       (and <code>&lt;Directory ~&gt;</code>)</li>
422
423       <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
424       simultaneously</li>
425
426       <li><code class="directive"><a href="./mod/core.html#location">&lt;Location&gt;</a></code>
427       and <code class="directive"><a href="./mod/core.html#locationmatch">&lt;LocationMatch&gt;</a></code> done simultaneously</li>
428
429       <li><code class="directive"><a href="./mod/core.html#if">&lt;If&gt;</a></code>
430       </li>
431
432     </ol>
433
434     <p>Apart from <code class="directive"><a href="./mod/core.html#directory">&lt;Directory&gt;</a></code>, each group is processed in
435     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)
436     is processed in the order shortest directory component to longest.
437     So for example, <code>&lt;Directory "/var/web/dir"&gt;</code> will
438     be processed before <code>&lt;Directory
439     "/var/web/dir/subdir"&gt;</code>.  If multiple <code class="directive"><a href="./mod/core.html#directory">&lt;Directory&gt;</a></code> sections apply
440     to the same directory they are processed in the configuration file
441     order. Configurations included via the <code class="directive"><a href="./mod/core.html#include">Include</a></code> directive will be treated as if
442     they were inside the including file at the location of the
443     <code class="directive"><a href="./mod/core.html#include">Include</a></code> directive.</p>
444
445     <p>Sections inside <code class="directive"><a href="./mod/core.html#virtualhost">&lt;VirtualHost&gt;</a></code> sections
446     are applied <em>after</em> the corresponding sections outside
447     the virtual host definition. This allows virtual hosts to
448     override the main server configuration.</p>
449
450     <p>When the request is served by <code class="module"><a href="./mod/mod_proxy.html">mod_proxy</a></code>, the
451     <code class="directive"><a href="./mod/mod_proxy.html#proxy">&lt;Proxy&gt;</a></code>
452     container takes the place of the <code class="directive"><a href="./mod/core.html#directory">&lt;Directory&gt;</a></code> container in the processing
453     order.</p>
454
455     <p>Later sections override earlier ones, however each module is responsible
456     for interpreting what form this override takes.  A later configuration section
457     with directives from a given module might cause a conceptual "merge" of some
458     directives, all directives, or a complete replacement of the modules
459     configuration with the module defaults and directives explicitly listed in
460     the later context.</p>
461
462 <div class="note"><h3>Technical Note</h3>
463       There is actually a
464       <code>&lt;Location&gt;</code>/<code>&lt;LocationMatch&gt;</code>
465       sequence performed just before the name translation phase
466       (where <code>Aliases</code> and <code>DocumentRoots</code>
467       are used to map URLs to filenames). The results of this
468       sequence are completely thrown away after the translation has
469       completed.
470 </div>
471
472 <h3><a name="merge-examples" id="merge-examples">Some Examples</a></h3>
473
474 <p>Below is an artificial example to show the order of
475 merging. Assuming they all apply to the request, the directives in
476 this example will be applied in the order A &gt; B &gt; C &gt; D &gt;
477 E.</p>
478
479 <pre class="prettyprint lang-config">&lt;Location "/"&gt;
480     E
481 &lt;/Location&gt;
482
483 &lt;Files "f.html"&gt;
484     D
485 &lt;/Files&gt;
486
487 &lt;VirtualHost *&gt;
488 &lt;Directory "/a/emphasis role="bold""&gt;
489     B
490 &lt;/Directory&gt;
491 &lt;/VirtualHost&gt;
492
493 &lt;DirectoryMatch "^.*b$"&gt;
494     C
495 &lt;/DirectoryMatch&gt;
496
497 &lt;Directory "/a/b&gt;
498     A
499 &lt;/Directory&gt;</pre>
500
501
502 <p>For a more concrete example, consider the following.  Regardless of
503 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
504 evaluated last and will allow unrestricted access to the server.  In
505 other words, order of merging is important, so be careful!</p>
506
507 <pre class="prettyprint lang-config">&lt;Location "/"&gt;
508     Require all granted
509 &lt;/Location&gt;
510
511 # Whoops!  This &lt;Directory&gt; section will have no effect
512 &lt;Directory "/"&gt;
513     &lt;RequireAll&gt;
514         Require all granted
515         Require not host badguy.example.com
516     &lt;/RequireAll&gt;
517 &lt;/Directory&gt;</pre>
518
519
520
521
522 </div></div>
523 <div class="bottomlang">
524 <p><span>Available Languages: </span><a href="./en/sections.html" title="English">&nbsp;en&nbsp;</a> |
525 <a href="./fr/sections.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
526 <a href="./ja/sections.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
527 <a href="./ko/sections.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
528 <a href="./tr/sections.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
529 </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>
530 <script type="text/javascript"><!--//--><![CDATA[//><!--
531 var comments_shortname = 'httpd';
532 var comments_identifier = 'http://httpd.apache.org/docs/trunk/sections.html';
533 (function(w, d) {
534     if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
535         d.write('<div id="comments_thread"><\/div>');
536         var s = d.createElement('script');
537         s.type = 'text/javascript';
538         s.async = true;
539         s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
540         (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
541     }
542     else {
543         d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>');
544     }
545 })(window, document);
546 //--><!]]></script></div><div id="footer">
547 <p class="apache">Copyright 2016 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>
548 <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[//><!--
549 if (typeof(prettyPrint) !== 'undefined') {
550     prettyPrint();
551 }
552 //--><!]]></script>
553 </body></html>