sections.html revision 57d0156f7bbd9ea3a72342cf9912aba61d118702
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync<html xmlns="http://www.w3.org/1999/xhtml">
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <head>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <meta name="generator" content="HTML Tidy, see www.w3.org" />
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <title>How Directory, Location and Files sections work</title>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync </head>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <body bgcolor="#FFFFFF" text="#000000" link="#0000FF"
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync vlink="#000080" alink="#FF0000">
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <!--#include virtual="header.html" -->
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <h1 align="CENTER">How Directory, Location and Files sections
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync work</h1>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <p>The sections <a
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync href="mod/core.html#directory"><code>&lt;Directory&gt;</code></a>,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <a
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync href="mod/core.html#location"><code>&lt;Location&gt;</code></a>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync and <a
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync href="mod/core.html#files"><code>&lt;Files&gt;</code></a> can
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync contain directives which only apply to specified directories,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync URLs or files respectively. Also htaccess files can be used
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync inside a directory to apply directives to that directory. This
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync document explains how these different sections differ and how
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync they relate to each other when Apache decides which directives
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync apply for a particular directory or request URL.</p>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <h2>Directives allowed in the sections</h2>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <p>Everything that is syntactically allowed in
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;Directory&gt;</code> is also allowed in
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;Location&gt;</code> (except a
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync sub-<code>&lt;Files&gt;</code> section). Semantically, however
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync some things, most notably <code>AllowOverride</code> and the
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync two options <code>FollowSymLinks</code> and
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>SymLinksIfOwnerMatch</code>, make no sense in
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;Location&gt;</code>,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;LocationMatch&gt;</code> or
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;DirectoryMatch&gt;</code>. The same for
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;Files&gt;</code> -- syntactically everything is fine,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync but semantically some things are different.</p>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <h2>How the sections are merged</h2>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <p>The order of merging is:</p>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <ol>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <li><code>&lt;Directory&gt;</code> (except regular
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync expressions) and .htaccess done simultaneously (with
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync .htaccess, if allowed, overriding
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;Directory&gt;</code>)</li>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <li><code>&lt;DirectoryMatch&gt;</code>, and
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;Directory&gt;</code> with regular expressions</li>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <li><code>&lt;Files&gt;</code> and
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;FilesMatch&gt;</code> done simultaneously</li>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <li><code>&lt;Location&gt;</code> and
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;LocationMatch&gt;</code> done simultaneously</li>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync </ol>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <p>Apart from <code>&lt;Directory&gt;</code>, each group is
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync processed in the order that they appear in the configuration
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync files. <code>&lt;Directory&gt;</code> (group 1 above) is
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync processed in the order shortest directory component to longest.
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync If multiple <code>&lt;Directory&gt;</code> sections apply to
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync the same directory they they are processed in the configuration
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync file order. The configuration files are read in the order
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync httpd.conf, srm.conf and access.conf. Configurations included
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync via the <code>Include</code> directive will be treated as if
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync they were inside the including file at the location of the
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>Include</code> directive.</p>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <p>Sections inside <code>&lt;VirtualHost&gt;</code> sections
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync are applied <em>after</em> the corresponding sections outside
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync the virtual host definition. This allows virtual hosts to
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync override the main server configuration.</p>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <p>Later sections override earlier ones.</p>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <h2>Notes about using sections</h2>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <p>The general guidelines are:</p>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <ul>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <li>If you are attempting to match objects at the filesystem
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync level then you must use <code>&lt;Directory&gt;</code> and/or
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;Files&gt;</code>.</li>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <li>If you are attempting to match objects at the URL level
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync then you must use <code>&lt;Location&gt;</code></li>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync </ul>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <p>But a notable exception is:</p>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <ul>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <li>proxy control is done via <code>&lt;Directory&gt;</code>.
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync This is a legacy mistake because the proxy existed prior to
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;Location&gt;</code>. A future version of the config
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync language should probably switch this to
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;Location&gt;</code>.</li>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync </ul>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <p>Note about .htaccess parsing:</p>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <ul>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <li>Modifying .htaccess parsing during Location doesn't do
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync anything because .htaccess parsing has already occurred.</li>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync </ul>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <p><code>&lt;Location&gt;</code> and symbolic links:</p>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <ul>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <li>It is not possible to use "<code>Options
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync FollowSymLinks</code>" or "<code>Options
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync SymLinksIfOwnerMatch</code>" inside a
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;Location&gt;</code>,
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;LocationMatch&gt;</code> or
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;DirectoryMatch&gt;</code> section (the options are
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync simply ignored). Using the options in question is only
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync possible inside a <code>&lt;Directory&gt;</code> section (or
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync a <code>.htaccess</code> file).</li>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync </ul>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <p><code>&lt;Files&gt;</code> and <code>Options</code>:</p>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <ul>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <li>Apache won't check for it, but using an
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>Options</code> directive inside a
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;Files&gt;</code> section has no effect.</li>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync </ul>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <p>Another note:</p>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <ul>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <li>There is actually a
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <code>&lt;Location&gt;</code>/<code>&lt;LocationMatch&gt;</code>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync sequence performed just before the name translation phase
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync (where <code>Aliases</code> and <code>DocumentRoots</code>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync are used to map URLs to filenames). The results of this
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync sequence are completely thrown away after the translation has
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync completed.</li>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync </ul>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync <!--#include virtual="footer.html" -->
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync </body>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync</html>
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync
b8e299dddd091ae24e0c08c45d91b8f937bd14d2vboxsync