1 <html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><!--
2 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
3 This file is generated from xml source: DO NOT EDIT
4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5 --><title>Configuration Sections - Apache HTTP Server</title><link href="./style/manual.css" type="text/css" rel="stylesheet"></head><body><blockquote><div align="center"><img src="./images/sub.gif" alt="[APACHE DOCUMENTATION]"><h3>Apache HTTP Server Version 2.0</h3></div><h1 align="center">Configuration Sections</h1> <p>Directives in the <a href="configuring.html">configuration files</a> may apply to the
6 entire server, or they may be restricted to apply only to particular
7 directories, files, hosts, or URLs. This document describes how to
8 use configuration section containers or <code>.htaccess</code> files
9 to change the scope of other configuration directives.</p>
10 <ul><li><a href="#types">Types of Configuration Section Containers</a></li><li><a href="#file-and-web">Filesystem and Webspace</a><ul><li><a href="#filesystem">Filesystem Containers</a></li><li><a href="#webspace">Webspace Containers</a></li><li><a href="#wildcards">Wildcards and Regular Expressions</a></li><li><a href="#whichwhen">What to use When</a></li></ul></li><li><a href="#virtualhost">Virtual Hosts</a></li><li><a href="#proxy">Proxy</a></li><li><a href="#whatwhere">What Directives are Allowed?</a></li><li><a href="#mergin">How the sections are merged</a><ul><li><a href="#merge-examples">Some Examples</a></li></ul></li></ul><hr><h2><a name="types">Types of Configuration Section Containers</a></h2>
12 <table border="1"><tr><td valign="top"><strong>Related Modules</strong><br><br><code><a href="./mod/core.html">core</a></code><br><code><a href="./mod/mod_proxy.html">mod_proxy</a></code><br></td><td valign="top"><strong>Related Directives</strong><br><br><a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a><br><a href="./mod/core.html#directorymatch" class="directive"><code class="directive"><DirectoryMatch></code></a><br><a href="./mod/core.html#files" class="directive"><code class="directive"><Files></code></a><br><a href="./mod/core.html#filesmatch" class="directive"><code class="directive"><FilesMatch></code></a><br><a href="./mod/core.html#ifdefine" class="directive"><code class="directive"><IfDefine></code></a><br><a href="./mod/core.html#ifmodule" class="directive"><code class="directive"><IfModule></code></a><br><a href="./mod/core.html#location" class="directive"><code class="directive"><Location></code></a><br><a href="./mod/core.html#locationmatch" class="directive"><code class="directive"><LocationMatch></code></a><br><a href="./mod/proxy.html#proxy" class="directive"><code class="directive"><Proxy></code></a><br><a href="./mod/core.html#virtualhost" class="directive"><code class="directive"><VirtualHost></code></a><br></td></tr></table>
14 <p>There are two basic types of containers. Most containers are
15 evaluated for each request. The enclosed directives are applied only
16 for those requests that match the containers. The <a href="./mod/core.html#ifdefine" class="directive"><code class="directive"><IfDefine></code></a> and <a href="./mod/core.html#ifmodule" class="directive"><code class="directive"><IfModule></code></a> containers, on the
17 other hand, are evaluated only at server startup and restart. If
18 their conditions are true at startup, then the enclosed directives
19 will apply to all requests. If the conditions are not true, the
20 enclosed directives will be ignored.</p>
22 <p>The <a href="./mod/core.html#ifdefine" class="directive"><code class="directive"><IfDefine></code></a> directive
23 encloses directives that will only be applied if an appropriate
24 parameter is defined on the <code>httpd</code> command line. For example,
25 with the following configuration, all requests will be redirected
26 to another site only if the server is started using
27 <code>httpd -DClosedForNow</code>:</p>
29 <blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
30 <IfDefine ClosedForNow><br>
31 Redirect / http://otherserver.example.com/<br>
33 </code></td></tr></table></blockquote>
35 <p>The <a href="./mod/core.html#ifmodule" class="directive"><code class="directive"><IfModule></code></a>
36 directive is very similar, except it encloses directives that will
37 only be applied if a particular module is available in the server.
38 The module must either be statically compiled in the server, or it
39 must be dynamically compiled and its <a href="./mod/mod_so.html#loadmodule" class="directive"><code class="directive">LoadModule</code></a> line must be earlier in the
40 configuration file. This directive should only be used if you need
41 your configuration file to work whether or not certain modules are
42 installed. It should not be used to enclose directives that you want
43 to work all the time, because it can suppress useful error messages
44 about missing modules.</p>
46 <p>In the following example, the <a href="./mod/mod_mime_magic.html#mimemagicfiles" class="directive"><code class="directive">MimeMagicFiles</code></a> directive will be
47 applied only if <code><a href="./mod/mod_mime_magic.html">mod_mime_magic</a></code> is available.</p>
49 <blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
50 <IfModule mod_mime_magic.c><br>
51 MimeMagicFile conf/magic<br>
53 </code></td></tr></table></blockquote>
55 <p>Both <a href="./mod/core.html#ifdefine" class="directive"><code class="directive"><IfDefine></code></a>
56 and <a href="./mod/core.html#ifmodule" class="directive"><code class="directive"><IfModule></code></a>
57 can apply negative conditions by preceding their test with "!".
58 Also, these sections can be nested to achieve more complex
60 <h2><a name="file-and-web">Filesystem and Webspace</a></h2>
62 <p>The most commonly used configuration section containers are the
63 ones that change the configuration of particular places in the
64 filesystem or webspace. First, it is important to understand the
65 difference between the two. The filesystem is the view of your disks
66 as seen by your operating system. For example, in a default install,
67 Apache resides at <code>/usr/local/apache2</code> in the Unix
68 filesystem or <code>"c:/Program Files/Apache Group/Apache2"</code> in
69 the Windows filesystem. (Note that forward slashes should always be
70 used as the path separator in Apache, even for Windows.) In contrast,
71 the webspace is the view of your site as delivered by the web server
72 and seen by the client. So the path <code>/dir/</code> in the
73 webspace corresponds to the path
74 <code>/usr/local/apache2/htdocs/dir/</code> in the filesystem of a
75 default Apache install on Unix. The webspace need not map directly to
76 the filesystem, since webpages may be generated dynamically
77 from databases or other locations.</p>
79 <h3><a name="filesystem">Filesystem Containers</a></h3>
81 <p>The <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a>
82 and <a href="./mod/core.html#files" class="directive"><code class="directive"><Files></code></a>
83 directives, along with their regex counterparts, apply directives to
84 parts of the filesystem. Directives enclosed in a <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a> section apply to
85 the named filesystem directory and all subdirectories of that
86 directory. The same effect can be obtained using <a href="howto/htaccess.html">.htaccess files</a>. For example, in the
87 following configuration, directory indexes will be enabled for the
88 <code>/var/web/dir1</code> directory and all subdirectories.</p>
90 <blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
91 <Directory /var/web/dir1><br>
94 </code></td></tr></table></blockquote>
96 <p>Directives enclosed in a <a href="./mod/core.html#files" class="directive"><code class="directive"><Files></code></a> section apply to any file with
97 the specified name, regardless of what directory it lies in.
98 So for example, the following configuration directives will,
99 when placed in the main section of the configuration file,
100 deny access to any file named <code>private.html</code> regardless
101 of where it is found.</p>
103 <blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
104 <Files private.html><br>
108 </code></td></tr></table></blockquote>
110 <p>To address files found in a particular part of the filesystem, the
111 <a href="./mod/core.html#files" class="directive"><code class="directive"><Files></code></a> and
112 <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a> sections
113 can be combined. For example, the following configuration will deny
114 access to <code>/var/web/dir1/private.html</code>,
115 <code>/var/web/dir1/subdir2/private.html</code>,
116 <code>/var/web/dir1/subdir3/private.html</code>, and any other instance
117 of <code>private.html</code> found under the <code>/var/web/dir1/</code>
120 <blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
121 <Directory /var/web/dir1><br>
122 <Files private.html><br>
127 </code></td></tr></table></blockquote>
130 <h3><a name="webspace">Webspace Containers</a></h3>
132 <p>The <a href="./mod/core.html#location" class="directive"><code class="directive"><Location></code></a>
133 directive and its regex counterpart, on the other hand, change the
134 configuration for content in the webspace. For example, the following
135 configuration prevents access to any URL-path that begins in /private.
136 In particular, it will apply to requests for
137 <code>http://yoursite.example.com/private</code>,
138 <code>http://yoursite.example.com/private123</code>, and
139 <code>http://yoursite.example.com/private/dir/file.html</code> as well
140 as any other requests starting with the <code>/private</code> string.</p>
142 <blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
143 <Location /private><br>
147 </code></td></tr></table></blockquote>
149 <p>The <a href="./mod/core.html#location" class="directive"><code class="directive"><Location></code></a>
150 directive need not have anything to do with the filesystem.
151 For example, the following example shows how to map a particular
152 URL to an internal Apache handler provided by <code><a href="./mod/mod_status.html">mod_status</a></code>.
153 No file called <code>server-status</code> needs to exist in the
156 <blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
157 <Location /server-status><br>
158 SetHandler server-status<br>
160 </code></td></tr></table></blockquote>
163 <h3><a name="wildcards">Wildcards and Regular Expressions</a></h3>
165 <p>The <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a>,
166 <a href="./mod/core.html#files" class="directive"><code class="directive"><Files></code></a>, and
167 <a href="./mod/core.html#location" class="directive"><code class="directive"><Location></code></a>
168 directives can each use the shell-style wildcard characters "?" to
169 match any single character, "*" to match any set of characters, and
170 character classes like [a-zA-Z] to match particular characters. This
171 is useful to apply the same configuration to a group of filesystem or
172 webspace locations. If even more flexible matching is required, each
173 container has a regular-expression (regex) counterpart <a href="./mod/core.html#directorymatch" class="directive"><code class="directive"><DirectoryMatch></code></a>, <a href="./mod/core.html#filesmatch" class="directive"><code class="directive"><FilesMatch></code></a>, and <a href="./mod/core.html#locationmatch" class="directive"><code class="directive"><LocationMatch></code></a> that allow
174 perl-compatible<a href="glossary.html#regex">regular expressions</a>
175 to be used in choosing the matches. But see the section below on
176 configuration merging to find out how using regex sections will change
177 how directives are applied.</p>
179 <p>A non-regex wildcard section that changes the configuration of
180 all user directories could look as follows:</p>
182 <blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
183 <Directory /home/*/public_html><br>
186 </code></td></tr></table></blockquote>
188 <p>Using regex sections, we can deny access to many types of image files
190 <blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
191 <FilesMatch \.(?i:gif|jpe?g|png)$><br>
195 </code></td></tr></table></blockquote>
199 <h3><a name="whichwhen">What to use When</a></h3>
201 <p>Choosing between filesystem containers and webspace containers is
202 actually quite easy. When applying directives to objects that reside
203 in the filesystem always use <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a> or <a href="./mod/core.html#files" class="directive"><code class="directive"><Files></code></a>. When applying directives to objects
204 that do not reside in the filesystem (such as a webpage generated from
205 a database), use <a href="./mod/core.html#location" class="directive"><code class="directive"><Location></code></a>.</p>
207 <p>It is important to never use <a href="./mod/core.html#location" class="directive"><code class="directive"><Location></code></a> when trying to restrict
208 access to objects in the filesystem. This is because many
209 different webspace locations (URLs) could map to the same filesystem
210 location, allowing your restrictions to be circumvented.
211 For example, consider the following configuration:</p>
213 <blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
214 <Location /dir/><br>
218 </code></td></tr></table></blockquote>
220 <p>This works fine if the request is for
221 <code>http://yoursite.example.com/dir/</code>. But what if you are on
222 a case-insensitive filesystem? Then your restriction could be easily
223 circumvented by requesting
224 <code>http://yoursite.example.com/DIR/</code>. The <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a> directive, in
225 contrast, will apply to any content served from that location,
226 regardless of how it is called. (An exception is filesystem links.
227 The same directory can be placed in more than one part of the
228 filesystem using symbolic links. The <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a> directive will follow the symbolic
229 link without resetting the pathname. Therefore, for the highest level
230 of security, symbolic links should be disabled with the appropriate
231 <a href="./mod/core.html#options" class="directive"><code class="directive">Options</code></a> directive.)</p>
233 <p>If you are, perhaps, thinking that none of this applies to you
234 because you use a case-sensitive filesystem, remember that there are
235 many other ways to map multiple webspace locations to the same
236 filesystem location. Therefore you should always use the filesystem
237 containers when you can. There is, however, one exception to this
238 rule. Putting configuration restrictions in a <code><Location
239 /></code> section is perfectly safe because this section will apply
240 to all requests regardless of the specific URL.</p>
243 <h2><a name="virtualhost">Virtual Hosts</a></h2>
245 <p>The <a href="./mod/core.html#virtualhost" class="directive"><code class="directive"><VirtualHost></code></a>
246 container encloses directives that apply to specific hosts.
247 This is useful when serving multiple hosts from the same machine
248 with a different configuration for each. For more information,
249 see the <a href="vhosts/">Virtual Host Documentation</a>.</p>
250 <h2><a name="proxy">Proxy</a></h2>
252 <p>The <a href="./mod/proxy.html#proxy" class="directive"><code class="directive"><Proxy></code></a>
253 container applies enclosed configuration directives only
254 to sites accessed through <code><a href="./mod/mod_proxy.html">mod_proxy</a></code>'s proxy server
255 that match the specified URL. For example, the following configuration
256 will prevent the proxy server from being used to access the
257 <code>cnn.com</code> website.</p>
259 <blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
260 <Proxy http://cnn.com/*><br>
264 </code></td></tr></table></blockquote>
265 <h2><a name="whatwhere">What Directives are Allowed?</a></h2>
267 <p>To find out what directives are allowed in what types of
268 configuration sections, check the <a href="mod/directive-dict.html#Context">Context</a> of the directive.
269 Everything that is allowed in
270 <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a>
271 sections is also syntactically allowed in
272 <a href="./mod/core.html#directorymatch" class="directive"><code class="directive"><DirectoryMatch></code></a>,
273 <a href="./mod/core.html#files" class="directive"><code class="directive"><Files></code></a>,
274 <a href="./mod/core.html#filesmatch" class="directive"><code class="directive"><FilesMatch></code></a>,
275 <a href="./mod/core.html#location" class="directive"><code class="directive"><Location></code></a>,
276 <a href="./mod/core.html#locationmatch" class="directive"><code class="directive"><LocationMatch></code></a>,
278 <a href="./mod/proxy.html#proxy" class="directive"><code class="directive"><Proxy></code></a>
279 sections. There are some exceptions, however.</p>
282 <li>The <a href="./mod/core.html#allowoverride" class="directive"><code class="directive">AllowOverride</code></a> directive
283 works only in <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a>
286 <li>The <code>FollowSymLinks</code> and
287 <code>SymLinksIfOwnerMatch</code> <a href="./mod/core.html#options" class="directive"><code class="directive">Options</code></a> work only in <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a> sections or
288 <code>.htaccess</code> files.</li>
290 <li>The <a href="./mod/core.html#options" class="directive"><code class="directive">Options</code></a> directive cannot
291 be used in <a href="./mod/core.html#files" class="directive"><code class="directive"><Files></code></a>
292 and <a href="./mod/core.html#filesmatch" class="directive"><code class="directive"><FilesMatch></code></a>
295 <h2><a name="mergin">How the sections are merged</a></h2>
297 <p>The configuration sections are applied in a very particular order.
298 Since this can have important effects on how configuration directives
299 are interpreted, it is important to understand how this works.</p>
301 <p>The order of merging is:</p>
304 <li> <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a> (except regular expressions)
305 and .htaccess done simultaneously (with .htaccess, if allowed,
306 overriding <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a>)</li>
308 <li><a href="./mod/core.html#directorymatch" class="directive"><code class="directive"><DirectoryMatch></code></a>
309 (and <code><Directory ~></code>)</li>
311 <li><a href="./mod/core.html#files" class="directive"><code class="directive"><Files></code></a> and <a href="./mod/core.html#filesmatch" class="directive"><code class="directive"><FilesMatch></code></a> done
314 <li><a href="./mod/core.html#location" class="directive"><code class="directive"><Location></code></a>
315 and <a href="./mod/core.html#locationmatch" class="directive"><code class="directive"><LocationMatch></code></a> done simultaneously</li>
318 <p>Apart from <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a>, each group is processed in
319 the order that they appear in the configuration files. <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a> (group 1 above)
320 is processed in the order shortest directory component to longest.
321 So for example, <code><Directory /var/web/dir></code> will
322 be processed before <code><Directory
323 /var/web/dir/subdir></code>. If multiple <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a> sections apply
324 to the same directory they are processed in the configuration file
325 order. Configurations included via the <a href="./mod/core.html#include" class="directive"><code class="directive">Include</code></a> directive will be treated as if
326 they were inside the including file at the location of the
327 <a href="./mod/core.html#include" class="directive"><code class="directive">Include</code></a> directive.</p>
329 <p>Sections inside <a href="./mod/core.html#virtualhost" class="directive"><code class="directive"><VirtualHost></code></a> sections
330 are applied <em>after</em> the corresponding sections outside
331 the virtual host definition. This allows virtual hosts to
332 override the main server configuration.</p>
334 <p>Later sections override earlier ones.</p>
336 <blockquote><table><tr><td bgcolor="#e0e5f5"><p align="center"><strong>Technical Note</strong></p>
338 <code><Location></code>/<code><LocationMatch></code>
339 sequence performed just before the name translation phase
340 (where <code>Aliases</code> and <code>DocumentRoots</code>
341 are used to map URLs to filenames). The results of this
342 sequence are completely thrown away after the translation has
344 </td></tr></table></blockquote>
346 <h3><a name="merge-examples">Some Examples</a></h3>
348 <p>Below is an artificial example to show the order of
349 merging. Assuming they all apply to the request, the directives in
350 this example will be applied in the order A > B > C > D >
353 <blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
354 <Location /><br>
356 </Location><br>
358 <Files f.html><br>
362 <VirtualHost *><br>
363 <Directory /a/b><br>
365 </Directory><br>
366 </VirtualHost><br>
368 <DirectoryMatch "^.*b$"><br>
370 </DirectoryMatch><br>
372 <Directory /a/b><br>
374 </Directory><br>
376 </code></td></tr></table></blockquote>
378 <p>For a more concrete example, consider the following. Regardless of
379 any access restrictions placed in <a href="./mod/core.html#directory" class="directive"><code class="directive"><Directory></code></a> sections, the <a href="./mod/core.html#location" class="directive"><code class="directive"><Location></code></a> section will be
380 evaluated last and will allow unrestricted access to the server. In
381 other words, order of merging is important, so be careful!</p>
383 <blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
384 <Location /><br>
387 </Location><br>
389 # Woops! This <Directory> section will have no effect<br>
390 <Directory /><br>
393 Deny from badguy.example.com<br>
395 </code></td></tr></table></blockquote>
399 <hr></blockquote><h3 align="center">Apache HTTP Server Version 2.0</h3><a href="./"><img src="./images/index.gif" alt="Index"></a><a href="./"><img src="./images/home.gif" alt="Home"></a></body></html>