286N/A<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
286N/A<
TITLE>How Directory, Location and Files sections work</
TITLE>
286N/A<!-- Background white, links blue (unvisited), navy (visited), red (active) --> 286N/A<
H1 ALIGN="CENTER">How Directory, Location and Files sections work</
H1>
286N/Adirectives which only apply to specified directories, URLs or files
286N/Arespectively. Also htaccess files can be used inside a directory to
286N/Aapply directives to that directory. This document explains how these
286N/Adifferent sections differ and how they relate to each other when
286N/AApache decides which directives apply for a particular directory or
286N/A<
H2>Directives allowed in the sections</
H2>
286N/A<
p>Everything that is syntactically allowed in
286N/A<
CODE><Directory></
CODE> is also allowed in
286N/A<
CODE><Location></
CODE> (except a sub-<
CODE><Files></
CODE>
286N/Asection). Semantically, however some things, most
286N/Anotably <
CODE>AllowOverride</
CODE> and the two options
286N/A<
CODE>FollowSymLinks</
CODE> and <
CODE>SymLinksIfOwnerMatch</
CODE>,
286N/Amake no sense in <
CODE><Location></
CODE>,
286N/A<
CODE><LocationMatch></
CODE> or <
CODE><DirectoryMatch></
CODE>.
286N/AThe same for <
CODE><Files></
CODE> -- syntactically everything
286N/Ais fine, but semantically some things are different.</
p>
286N/A<
H2>How the sections are merged</
H2>
286N/A<
p>The order of merging is:</
p>
286N/A <
CODE><Directory></
CODE> (except regular expressions) and
286N/A .htaccess done simultaneously (with .htaccess, if allowed, overriding
286N/A <
CODE><Directory></
CODE>)
286N/A <
CODE><DirectoryMatch></
CODE>, and
286N/A <
CODE><Directory></
CODE> with regular expressions
286N/A <
LI><
CODE><Files></
CODE> and <
CODE><FilesMatch></
CODE> done
286N/A <
LI><
CODE><Location></
CODE> and <
CODE><LocationMatch></
CODE> done
286N/A<
p>Apart from <
CODE><Directory></
CODE>, each group is processed in
286N/Athe order that they appear in the configuration
286N/Afiles. <
CODE><Directory></
CODE> (group 1 above) is processed in
286N/Athe order shortest directory component to longest. If multiple
286N/A<
CODE><Directory></
CODE> sections apply to the same directory
286N/Athey they are processed in the configuration file order. The
286N/Adirective will be treated as if they were inside the including file
286N/Aat the location of the <
CODE>Include</
CODE> directive.</
p>
286N/A<
p>Sections inside <
CODE><VirtualHost></
CODE> sections are applied
286N/A<
EM>after</
EM> the corresponding sections outside the virtual host
286N/Adefinition. This allows virtual hosts to override the main server
286N/A<
p>Later sections override earlier ones.</
p>
286N/A<
H2>Notes about using sections</
H2>
286N/A<
p>The general guidelines are:</
p>
286N/A If you are attempting to match objects at the filesystem level
286N/A then you must use <
CODE><Directory></
CODE>
and/
or 286N/A <
CODE><Files></
CODE>.
286N/A If you are attempting to match objects at the URL level then you
286N/A must use <
CODE><Location></
CODE>
286N/A<
p>But a notable exception is:</
p>
286N/A proxy control is done via <
CODE><Directory></
CODE>. This is
286N/A a legacy mistake because the proxy existed prior to
286N/A <
CODE><Location></
CODE>. A future version of the config
286N/A language should probably switch this to
286N/A <
CODE><Location></
CODE>.
286N/A<
p>Note about .htaccess parsing:</
p>
286N/A Modifying .htaccess parsing during Location doesn't do
286N/A anything because .htaccess parsing has already occurred.
286N/A<
p><
CODE><Location></
CODE> and symbolic links:</
p>
286N/A It is not possible to use "<
CODE>Options FollowSymLinks</
CODE>"
286N/A or "<
CODE>Options SymLinksIfOwnerMatch</
CODE>" inside a
286N/A <
CODE><Location></
CODE>, <
CODE><LocationMatch></
CODE>
286N/A or <
CODE><DirectoryMatch></
CODE> section
286N/A (the options are simply ignored).
286N/A Using the options in question is only possible inside a
286N/A <
CODE><Directory></
CODE> section (or a <
CODE>.htaccess</
CODE> file).
286N/A<
p><
CODE><Files></
CODE> and <
CODE>Options</
CODE>:</
p>
286N/A Apache won't check for it, but using an <
CODE>Options</
CODE>
286N/A directive inside a <
CODE><Files></
CODE> section has no effect.
286N/A <
CODE><Location></
CODE>/<
CODE><LocationMatch></
CODE>
286N/A sequence performed just before the name translation phase (where
286N/A <
CODE>Aliases</
CODE> and <
CODE>DocumentRoots</
CODE> are used to
286N/A map URLs to filenames). The results of this sequence are
286N/A completely thrown away after the translation has completed.