1<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
6<html xmlns="http://www.w3.org/1999/xhtml">
7  <head>
8    <meta name="generator" content="HTML Tidy, see www.w3.org" />
9
10    <title>How Directory, Location and Files sections work</title>
11  </head>
12  <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
13
14  <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
15  vlink="#000080" alink="#FF0000">
16        <div align="CENTER">
17      <img src="images/sub.gif" alt="[APACHE DOCUMENTATION]" />
18
19      <h3>Apache HTTP Server</h3>
20    </div>
21
22
23
24    <h1 align="CENTER">How Directory, Location and Files sections
25    work</h1>
26
27    <p>The sections <a
28    href="mod/core.html#directory"><code>&lt;Directory&gt;</code></a>,
29    <a
30    href="mod/core.html#location"><code>&lt;Location&gt;</code></a>
31    and <a
32    href="mod/core.html#files"><code>&lt;Files&gt;</code></a> can
33    contain directives which only apply to specified directories,
34    URLs or files respectively. Also htaccess files can be used
35    inside a directory to apply directives to that directory. This
36    document explains how these different sections differ and how
37    they relate to each other when Apache decides which directives
38    apply for a particular directory or request URL.</p>
39
40    <h2>Directives allowed in the sections</h2>
41
42    <p>Everything that is syntactically allowed in
43    <code>&lt;Directory&gt;</code> is also allowed in
44    <code>&lt;Location&gt;</code> (except a
45    sub-<code>&lt;Files&gt;</code> section). Semantically, however
46    some things, most notably <code>AllowOverride</code> and the
47    two options <code>FollowSymLinks</code> and
48    <code>SymLinksIfOwnerMatch</code>, make no sense in
49    <code>&lt;Location&gt;</code>,
50    <code>&lt;LocationMatch&gt;</code> or
51    <code>&lt;DirectoryMatch&gt;</code>. The same for
52    <code>&lt;Files&gt;</code> -- syntactically everything is fine,
53    but semantically some things are different.</p>
54
55    <h2>How the sections are merged</h2>
56
57    <p>The order of merging is:</p>
58
59    <ol>
60      <li><code>&lt;Directory&gt;</code> (except regular
61      expressions) and .htaccess done simultaneously (with
62      .htaccess, if allowed, overriding
63      <code>&lt;Directory&gt;</code>)</li>
64
65      <li><code>&lt;DirectoryMatch&gt;</code>, and
66      <code>&lt;Directory&gt;</code> with regular expressions</li>
67
68      <li><code>&lt;Files&gt;</code> and
69      <code>&lt;FilesMatch&gt;</code> done simultaneously</li>
70
71      <li><code>&lt;Location&gt;</code> and
72      <code>&lt;LocationMatch&gt;</code> done simultaneously</li>
73    </ol>
74
75    <p>Apart from <code>&lt;Directory&gt;</code>, each group is
76    processed in the order that they appear in the configuration
77    files. <code>&lt;Directory&gt;</code> (group 1 above) is
78    processed in the order shortest directory component to longest.
79    If multiple <code>&lt;Directory&gt;</code> sections apply to
80    the same directory they are processed in the configuration
81    file order. The configuration files are read in the order
82    httpd.conf, srm.conf and access.conf. Configurations included
83    via the <code>Include</code> directive will be treated as if
84    they were inside the including file at the location of the
85    <code>Include</code> directive.</p>
86
87    <p>Sections inside <code>&lt;VirtualHost&gt;</code> sections
88    are applied <em>after</em> the corresponding sections outside
89    the virtual host definition. This allows virtual hosts to
90    override the main server configuration. (Note: this only works
91    correctly from 1.2.2 and 1.3a2 onwards. Before those releases
92    sections inside virtual hosts were applied <em>before</em> the
93    main server).</p>
94
95    <p>Later sections override earlier ones.</p>
96
97    <h2>Notes about using sections</h2>
98
99    <p>The general guidelines are:</p>
100
101    <ul>
102      <li>If you are attempting to match objects at the filesystem
103      level then you must use <code>&lt;Directory&gt;</code> and/or
104      <code>&lt;Files&gt;</code>.</li>
105
106      <li>If you are attempting to match objects at the URL level
107      then you must use <code>&lt;Location&gt;</code></li>
108    </ul>
109
110    <p>But a notable exception is:</p>
111
112    <ul>
113      <li>proxy control is done via <code>&lt;Directory&gt;</code>.
114      This is a legacy mistake because the proxy existed prior to
115      <code>&lt;Location&gt;</code>. A future version of the config
116      language should probably switch this to
117      <code>&lt;Location&gt;</code>.</li>
118    </ul>
119
120    <p>Note about .htaccess parsing:</p>
121
122    <ul>
123      <li>Modifying .htaccess parsing during Location doesn't do
124      anything because .htaccess parsing has already occurred.</li>
125    </ul>
126
127    <p><code>&lt;Location&gt;</code> and symbolic links:</p>
128
129    <ul>
130      <li>It is not possible to use "<code>Options
131      FollowSymLinks</code>" or "<code>Options
132      SymLinksIfOwnerMatch</code>" inside a
133      <code>&lt;Location&gt;</code>,
134      <code>&lt;LocationMatch&gt;</code> or
135      <code>&lt;DirectoryMatch&gt;</code> section (the options are
136      simply ignored). Using the options in question is only
137      possible inside a <code>&lt;Directory&gt;</code> section (or
138      a <code>.htaccess</code> file).</li>
139    </ul>
140
141    <p><code>&lt;Files&gt;</code> and <code>Options</code>:</p>
142
143    <ul>
144      <li>Apache won't check for it, but using an
145      <code>Options</code> directive inside a
146      <code>&lt;Files&gt;</code> section has no effect.</li>
147    </ul>
148
149    <p>Another note:</p>
150
151    <ul>
152      <li>There is actually a
153      <code>&lt;Location&gt;</code>/<code>&lt;LocationMatch&gt;</code>
154      sequence performed just before the name translation phase
155      (where <code>Aliases</code> and <code>DocumentRoots</code>
156      are used to map URLs to filenames). The results of this
157      sequence are completely thrown away after the translation has
158      completed.</li>
159    </ul>
160        <hr />
161
162    <h3 align="CENTER">Apache HTTP Server</h3>
163    <a href="./"><img src="images/index.gif" alt="Index" /></a>
164
165  </body>
166</html>
167
168
169
170