sections.html revision d61d254ea3c16e6c69a847d0332153a090cee6e4
286N/A<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
286N/A<HTML><HEAD>
286N/A<TITLE>How Directory, Location and Files sections work</TITLE>
286N/A</HEAD>
286N/A
286N/A<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
286N/A<BODY
286N/A BGCOLOR="#FFFFFF"
286N/A TEXT="#000000"
286N/A LINK="#0000FF"
286N/A VLINK="#000080"
286N/A ALINK="#FF0000"
286N/A>
286N/A<!--#include virtual="header.html" -->
286N/A
286N/A<H1 ALIGN="CENTER">How Directory, Location and Files sections work</H1>
286N/A
286N/A<p>The sections <A
286N/AHREF="mod/core.html#directory"><CODE>&lt;Directory&gt;</CODE></A>, <A
286N/AHREF="mod/core.html#location"><CODE>&lt;Location&gt;</CODE></A> and <A
286N/AHREF="mod/core.html#files"><CODE>&lt;Files&gt;</CODE></A> can contain
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/Arequest URL.</p>
286N/A
286N/A<H2>Directives allowed in the sections</H2>
286N/A
286N/A<p>Everything that is syntactically allowed in
286N/A<CODE>&lt;Directory&gt;</CODE> is also allowed in
286N/A<CODE>&lt;Location&gt;</CODE> (except a sub-<CODE>&lt;Files&gt;</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>&lt;Location&gt;</CODE>,
286N/A<CODE>&lt;LocationMatch&gt;</CODE> or <CODE>&lt;DirectoryMatch&gt;</CODE>.
286N/AThe same for <CODE>&lt;Files&gt;</CODE> -- syntactically everything
286N/Ais fine, but semantically some things are different.</p>
286N/A
286N/A<H2>How the sections are merged</H2>
286N/A
286N/A<p>The order of merging is:</p>
286N/A
286N/A<OL>
286N/A
286N/A<LI>
286N/A
286N/A <CODE>&lt;Directory&gt;</CODE> (except regular expressions) and
286N/A .htaccess done simultaneously (with .htaccess, if allowed, overriding
286N/A <CODE>&lt;Directory&gt;</CODE>)
286N/A
286N/A</LI>
286N/A
286N/A<LI>
286N/A <CODE>&lt;DirectoryMatch&gt;</CODE>, and
286N/A <CODE>&lt;Directory&gt;</CODE> with regular expressions
286N/A
286N/A</LI>
286N/A
286N/A <LI><CODE>&lt;Files&gt;</CODE> and <CODE>&lt;FilesMatch&gt;</CODE> done
286N/A simultaneously
286N/A </LI>
286N/A
286N/A <LI><CODE>&lt;Location&gt;</CODE> and <CODE>&lt;LocationMatch&gt;</CODE> done
286N/A simultaneously
286N/A </LI>
286N/A
286N/A</OL>
286N/A
286N/A<p>Apart from <CODE>&lt;Directory&gt;</CODE>, each group is processed in
286N/Athe order that they appear in the configuration
286N/Afiles. <CODE>&lt;Directory&gt;</CODE> (group 1 above) is processed in
286N/Athe order shortest directory component to longest. If multiple
286N/A<CODE>&lt;Directory&gt;</CODE> sections apply to the same directory
286N/Athey they are processed in the configuration file order. The
286N/Aconfiguration files are read in the order httpd.conf, srm.conf and
286N/Aaccess.conf. Configurations included via the <CODE>Include</CODE>
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
286N/A<p>Sections inside <CODE>&lt;VirtualHost&gt;</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/Aconfiguration.</p>
286N/A
286N/A<p>Later sections override earlier ones.</p>
286N/A
286N/A<H2>Notes about using sections</H2>
286N/A
286N/A<p>The general guidelines are:</p>
286N/A
286N/A<UL>
286N/A<LI>
286N/A If you are attempting to match objects at the filesystem level
286N/A then you must use <CODE>&lt;Directory&gt;</CODE> and/or
286N/A <CODE>&lt;Files&gt;</CODE>.
286N/A</LI>
286N/A
286N/A<LI>
286N/A If you are attempting to match objects at the URL level then you
286N/A must use <CODE>&lt;Location&gt;</CODE>
286N/A</LI>
286N/A</UL>
286N/A
286N/A<p>But a notable exception is:</p>
286N/A
286N/A<UL>
286N/A<LI>
286N/A proxy control is done via <CODE>&lt;Directory&gt;</CODE>. This is
286N/A a legacy mistake because the proxy existed prior to
286N/A <CODE>&lt;Location&gt;</CODE>. A future version of the config
286N/A language should probably switch this to
286N/A <CODE>&lt;Location&gt;</CODE>.
286N/A</LI>
286N/A</UL>
286N/A
286N/A<p>Note about .htaccess parsing:</p>
286N/A
286N/A<UL>
286N/A<LI>
286N/A Modifying .htaccess parsing during Location doesn't do
286N/A anything because .htaccess parsing has already occurred.
286N/A</UL>
286N/A
286N/A<p><CODE>&lt;Location&gt;</CODE> and symbolic links:</p>
286N/A
286N/A<UL>
286N/A<LI>
286N/A It is not possible to use "<CODE>Options FollowSymLinks</CODE>"
286N/A or "<CODE>Options SymLinksIfOwnerMatch</CODE>" inside a
286N/A <CODE>&lt;Location&gt;</CODE>, <CODE>&lt;LocationMatch&gt;</CODE>
286N/A or <CODE>&lt;DirectoryMatch&gt;</CODE> section
286N/A (the options are simply ignored).
286N/A Using the options in question is only possible inside a
286N/A <CODE>&lt;Directory&gt;</CODE> section (or a <CODE>.htaccess</CODE> file).
286N/A</UL>
286N/A
286N/A<p><CODE>&lt;Files&gt;</CODE> and <CODE>Options</CODE>:</p>
286N/A
286N/A<UL>
286N/A<LI>
286N/A Apache won't check for it, but using an <CODE>Options</CODE>
286N/A directive inside a <CODE>&lt;Files&gt;</CODE> section has no effect.
286N/A</UL>
286N/A
286N/A<p>Another note:</p>
286N/A
286N/A<UL>
286N/A<LI>
286N/A There is actually a
286N/A <CODE>&lt;Location&gt;</CODE>/<CODE>&lt;LocationMatch&gt;</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.
286N/A</LI>
286N/A</UL>
286N/A
286N/A<!--#include virtual="footer.html" -->
286N/A</BODY>
286N/A</HTML>
286N/A