1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
3 <TITLE>How Directory, Location and Files sections work</TITLE>
6 <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
14 <!--#include virtual="header.html" -->
15 <H1 ALIGN="CENTER">How Directory, Location and Files sections work</H1>
18 HREF="mod/core.html#directory"><CODE><Directory></CODE></A>, <A
19 HREF="mod/core.html#location"><CODE><Location></CODE></A> and <A
20 HREF="mod/core.html#files"><CODE><Files></CODE></A> can contain
21 directives which only apply to specified directories, URLs or files
22 respectively. Also htaccess files can be used inside a directory to
23 apply directives to that directory. This document explains how these
24 different sections differ and how they relate to each other when
25 Apache decides which directives apply for a particular directory or
28 <H2>Directives allowed in the sections</H2>
30 Everything that is syntactically allowed in
31 <CODE><Directory></CODE> is also allowed in
32 <CODE><Location></CODE> (except a sub-<CODE><Files></CODE>
33 section, but the code doesn't test for that, Lars has an open bug
34 report on that). Semantically however some things, and the most
35 notable is AllowOverride, make no sense in
36 <CODE><Location></CODE>. The same for
37 <CODE><Files></CODE> -- syntactically everything is fine, but
38 semantically some things are different.
40 <H2>How the sections are merged</H2>
42 The order of merging is:
48 <CODE><Directory></CODE> (except regular expressions) and
49 .htaccess done simultaneously (with .htaccess overriding
50 <CODE><Directory></CODE>)
55 <CODE><DirectoryMatch></CODE>, and
56 <CODE><Directory></CODE> with regular expressions
60 <LI><CODE><Files></CODE> and <CODE><FilesMatch></CODE> done simultaneously
63 <LI><CODE><Location></CODE> and <CODE><LocationMatch></CODE> done simultaneously
68 Apart from <CODE><Directory></CODE>, each group is processed in
69 the order that they appear in the configuration
70 files. <CODE><Directory></CODE> (group 1 above) is processed in
71 the order shortest directory component to longest. If multiple
72 <CODE><Directory></CODE> sections apply to the same directory
73 they they are processed in the configuration file order. The
74 configuration files are read in the order httpd.conf, srm.conf and
75 access.conf. Configurations included via the <CODE>Include</CODE>
76 directive will be treated as if they where inside the including file
77 at the location of the <CODE>Include</CODE> directive.
81 Sections inside <CODE><VirtualHost></CODE> sections are applied
82 <EM>after</EM> the corresponding sections outside the virtual host
83 definition. This allows virtual hosts to override the main server
84 configuration. (Note: this only works correctly from 1.2.2 and 1.3a2
85 onwards. Before those releases sections inside virtual hosts were
86 applied <EM>before</EM> the main server).
88 <H2>Notes about using sections</H2>
90 The general guidelines are:
96 If you are attempting to match objects at the filesystem level
97 then you must use <CODE><Directory></CODE> and/or
98 <CODE><Files></CODE>.
102 If you are attempting to match objects at the URL level then you
103 must use <CODE><Location></CODE>
107 But a notable exception is:
111 proxy control is done via <CODE><Directory></CODE>. This is
112 a legacy mistake because the proxy existed prior to
113 <CODE><Location></CODE>. A future version of the config
114 language should probably switch this to
115 <CODE><Location></CODE>.
119 Note also that modifying .htaccess parsing during Location doesn't do
120 anything because .htaccess parsing has already occurred.
130 <CODE><Location></CODE>/<CODE><LocationMatch></CODE>
131 sequence performed just before the name translation phase (where
132 <CODE>Aliases</CODE> and <CODE>DocumentRoots</CODE> are used to
133 map URLs to filenames). The results of this sequence are
134 completely thrown away after the translation has completed.
138 <!--#include virtual="footer.html" -->