sections.html.en revision c3b8fe2327e10aafbf419315dca8a683c1974327
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<html><head><META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><!--
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila This file is generated from xml source: DO NOT EDIT
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila --><title>Configuration Sections - Apache HTTP Server</title><link href="/style/manual.css" type="text/css" rel="stylesheet"></head><body><blockquote><div align="center"><img src="/images/sub.gif" alt="[APACHE DOCUMENTATION]"><h3>Apache HTTP Server Version 2.0</h3></div><h1 align="center">Configuration Sections</h1> <p>Directives in the <a href="configuring.html">configuration files</a> may apply to the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaentire server, or they may be restricted to apply only to particular
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huoviladirectories, files, hosts, or URLs. This document describes how to
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilause configuration section containers or <code>.htaccess</code> files
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilato change the scope of other configuration directives.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<ul><li><a href="#types">Types of Configuration Section Containers</a></li><li><a href="#file-and-web">Filesystem and Webspace</a><ul><li><a href="#filesystem">Filesystem Containers</a></li><li><a href="#webspace">Webspace Containers</a></li><li><a href="#wildcards">Wildcards and Regular Expressions</a></li><li><a href="#whichwhen">What to use When</a></li></ul></li><li><a href="#virtualhost">Virtual Hosts</a></li><li><a href="#proxy">Proxy</a></li><li><a href="#whatwhere">What Directives are Allowed?</a></li><li><a href="#mergin">How the sections are merged</a><ul><li><a href="#merge-examples">Some Examples</a></li></ul></li></ul><hr><h2><a name="types">Types of Configuration Section Containers</a></h2>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<table border="1"><tr><td valign="top"><strong>Related Modules</strong><br><br><code><a href="/mod/core.html">core</a></code><br><code><a href="/mod/mod_proxy.html">mod_proxy</a></code><br></td><td valign="top"><strong>Related Directives</strong><br><br><a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a><br><a href="/mod/core.html#directorymatch" class="directive"><code class="directive">&lt;DirectoryMatch&gt;</code></a><br><a href="/mod/core.html#files" class="directive"><code class="directive">&lt;Files&gt;</code></a><br><a href="/mod/core.html#filesmatch" class="directive"><code class="directive">&lt;FilesMatch&gt;</code></a><br><a href="/mod/core.html#ifdefine" class="directive"><code class="directive">&lt;IfDefine&gt;</code></a><br><a href="/mod/core.html#ifmodule" class="directive"><code class="directive">&lt;IfModule&gt;</code></a><br><a href="/mod/core.html#location" class="directive"><code class="directive">&lt;Location&gt;</code></a><br><a href="/mod/core.html#locationmatch" class="directive"><code class="directive">&lt;LocationMatch&gt;</code></a><br><a href="/mod/proxy.html#proxy" class="directive"><code class="directive">&lt;Proxy&gt;</code></a><br><a href="/mod/core.html#virtualhost" class="directive"><code class="directive">&lt;VirtualHost&gt;</code></a><br></td></tr></table>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>There are two basic types of containers. Most containers are
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaevaluated for each request. The enclosed directives are applied only
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilafor those requests that match the containers. The <a href="/mod/core.html#ifdefine" class="directive"><code class="directive">&lt;IfDefine&gt;</code></a> and <a href="/mod/core.html#ifmodule" class="directive"><code class="directive">&lt;IfModule&gt;</code></a> containers, on the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaother hand, are evaluated only at server startup and restart. If
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilatheir conditions are true at startup, then the enclosed directives
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilawill apply to all requests. If the conditions are not true, the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaenclosed directives will be ignored.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>The <a href="/mod/core.html#ifdefine" class="directive"><code class="directive">&lt;IfDefine&gt;</code></a> directive
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaencloses directives that will only be applied if an appropriate
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaparameter is defined on the <code>httpd</code> command line. For example,
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilawith the following configuration, all requests will be redirected
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilato another site only if the server is started using
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<code>httpd -DClosedForNow</code>:</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;IfDefine ClosedForNow&gt;<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaRedirect / http://otherserver.example.com/<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;/IfDefine&gt;
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila</code></td></tr></table></blockquote>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>The <a href="/mod/core.html#ifmodule" class="directive"><code class="directive">&lt;IfModule&gt;</code></a>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huoviladirective is very similar, except it encloses directives that will
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaonly be applied if a particular module is available in the server.
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaThe module must either be statically compiled in the server, or it
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilamust be dynamically compiled and its <a href="/mod/mod_so.html#loadmodule" class="directive"><code class="directive">LoadModule</code></a> line must be earlier in the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaconfiguration file. This directive should only be used if you need
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilayour configuration file to work whether or not certain modules are
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilainstalled. It should not be used to enclose directives that you want
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilato work all the time, because it can suppress useful error messages
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaabout missing modules.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>In the following example, the <a href="/mod/mod_mime_magic.html#mimemagicfiles" class="directive"><code class="directive">MimeMagicFiles</code></a> directive will be
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaapplied only if <code><a href="/mod/mod_mime_magic.html">mod_mime_magic</a></code> is available.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;IfModule mod_mime_magic.c&gt;<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaMimeMagicFile conf/magic<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;/IfModule&gt;
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila</code></td></tr></table></blockquote>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>Both <a href="/mod/core.html#ifdefine" class="directive"><code class="directive">&lt;IfDefine&gt;</code></a>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaand <a href="/mod/core.html#ifmodule" class="directive"><code class="directive">&lt;IfModule&gt;</code></a>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilacan apply negative conditions by preceding their test with "!".
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaAlso, these sections can be nested to achieve more complex
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilarestrictions.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<h2><a name="file-and-web">Filesystem and Webspace</a></h2>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>The most commonly used configuration section containers are the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaones that change the configuration of particular places in the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilafilesystem or webspace. First, it is important to understand the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huoviladifference between the two. The filesystem is the view of your disks
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaas seen by your operating system. For example, in a default install,
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaApache resides at <code>/usr/local/apache2</code> in the Unix
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilafilesystem or <code>"c:/Program Files/Apache Group/Apache2"</code> in
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilathe Windows filesystem. (Note that forward slashes should always be
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaused as the path separator in Apache, even for Windows.) In contrast,
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilathe webspace is the view of your site as delivered by the web server
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaand seen by the client. So the path <code>/dir/</code> in the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilawebspace corresponds to the path
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<code>/usr/local/apache2/htdocs/dir/</code> in the filesystem of a
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huoviladefault Apache install on Unix. The webspace need not map directly to
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilathe filesystem, since webpages may be generated dynamically
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilafrom databases or other locations.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<h3><a name="filesystem">Filesystem Containers</a></h3>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>The <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaand <a href="/mod/core.html#files" class="directive"><code class="directive">&lt;Files&gt;</code></a>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huoviladirectives, along with their regex counterparts, apply directives to
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaparts of the filesystem. Directives enclosed in a <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a> section apply to
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilathe named filesystem directory and all subdirectories of that
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huoviladirectory. The same effect can be obtained using <a href="howto/htaccess.html">.htaccess files</a>. For example, in the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilafollowing configuration, directory indexes will be enabled for the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<code>/var/web/dir1</code> directory and all subdirectories.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;Directory /var/web/dir1&gt;<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaOptions +Indexes<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;/Directory&gt;
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila</code></td></tr></table></blockquote>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>Directives enclosed in a <a href="/mod/core.html#files" class="directive"><code class="directive">&lt;Files&gt;</code></a> section apply to any file with
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilathe specified name, regardless of what directory it lies in.
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaSo for example, the following configuration directives will,
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilawhen placed in the main section of the configuration file,
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huoviladeny access to any file named <code>private.html</code> regardless
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaof where it is found.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;Files private.html&gt;<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaOrder allow,deny<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaDeny from all<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;/Files&gt;
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila</code></td></tr></table></blockquote>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>To address files found in a particular part of the filesystem, the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<a href="/mod/core.html#files" class="directive"><code class="directive">&lt;Files&gt;</code></a> and
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a> sections
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilacan be combined. For example, the following configuration will deny
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaaccess to <code>/var/web/dir1/private.html</code>,
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<code>/var/web/dir1/subdir2/private.html</code>,
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<code>/var/web/dir1/subdir3/private.html</code>, and any other instance
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaof <code>private.html</code> found under the <code>/var/web/dir1/</code>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huoviladirectory.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;Directory /var/web/dir1&gt;<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;Files private.html&gt;<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaOrder allow,deny<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaDeny from all<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;/Files&gt;<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;/Directory&gt;
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila</code></td></tr></table></blockquote>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<h3><a name="webspace">Webspace Containers</a></h3>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>The <a href="/mod/core.html#location" class="directive"><code class="directive">&lt;Location&gt;</code></a>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huoviladirective and its regex counterpart, on the other hand, change the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaconfiguration for content in the webspace. For example, the following
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaconfiguration prevents access to any URL-path that begins in /private.
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaIn particular, it will apply to requests for
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<code>http://yoursite.example.com/private</code>,
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<code>http://yoursite.example.com/private123</code>, and
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<code>http://yoursite.example.com/private/dir/file.html</code> as well
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaas any other requests starting with the <code>/private</code> string.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;Location /private&gt;<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaOrder Allow,Deny<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaDeny from all<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;/Location&gt;
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila</code></td></tr></table></blockquote>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>The <a href="/mod/core.html#location" class="directive"><code class="directive">&lt;Location&gt;</code></a>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huoviladirective need not have anything to do with the filesystem.
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaFor example, the following example shows how to map a particular
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaURL to an internal Apache handler provided by <code><a href="/mod/mod_status.html">mod_status</a></code>.
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaNo file called <code>server-status</code> needs to exist in the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilafilesystem.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;Location /server-status&gt;<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaSetHandler server-status<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;/Location&gt;
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila</code></td></tr></table></blockquote>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<h3><a name="wildcards">Wildcards and Regular Expressions</a></h3>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>The <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a>,
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<a href="/mod/core.html#files" class="directive"><code class="directive">&lt;Files&gt;</code></a>, and
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<a href="/mod/core.html#location" class="directive"><code class="directive">&lt;Location&gt;</code></a>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huoviladirectives can each use the shell-style wildcard characters "?" to
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilamatch any single character, "*" to match any set of characters, and
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilacharacter classes like [a-zA-Z] to match particular characters. This
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilais useful to apply the same configuration to a group of filesystem or
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilawebspace locations. If even more flexible matching is required, each
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilacontainer has a regular-expression (regex) counterpart <a href="/mod/core.html#directorymatch" class="directive"><code class="directive">&lt;DirectoryMatch&gt;</code></a>, <a href="/mod/core.html#filesmatch" class="directive"><code class="directive">&lt;FilesMatch&gt;</code></a>, and <a href="/mod/core.html#locationmatch" class="directive"><code class="directive">&lt;LocationMatch&gt;</code></a> that allow
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaperl-compatible<a href="glossary.html#regex">regular expressions</a>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilato be used in choosing the matches. But see the section below on
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaconfiguration merging to find out how using regex sections will change
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilahow directives are applied.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>A non-regex wildcard section that changes the configuration of
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaall user directories could look as follows:</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;Directory /home/*/public_html&gt;<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaOptions Indexes<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;/Directory&gt;
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila</code></td></tr></table></blockquote>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>Using regex sections, we can deny access to many types of image files
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaat once:</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;FilesMatch \.(?i:gif|jpe?g|png)$&gt;<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaOrder allow,deny<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaDeny from all<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;/FilesMatch&gt;
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila</code></td></tr></table></blockquote>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<h3><a name="whichwhen">What to use When</a></h3>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>Choosing between filesystem containers and webspace containers is
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaactually quite easy. When applying directives to objects that reside
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilain the filesystem always use <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a> or <a href="/mod/core.html#files" class="directive"><code class="directive">&lt;Files&gt;</code></a>. When applying directives to objects
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilathat do not reside in the filesystem (such as a webpage generated from
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaa database), use <a href="/mod/core.html#location" class="directive"><code class="directive">&lt;Location&gt;</code></a>.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>It is important to never use <a href="/mod/core.html#location" class="directive"><code class="directive">&lt;Location&gt;</code></a> when trying to restrict
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaaccess to objects in the filesystem. This is because many
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huoviladifferent webspace locations (URLs) could map to the same filesystem
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilalocation, allowing your restrictions to be circumvented.
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaFor example, consider the following configuration:</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;Location /dir/&gt;<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaOrder allow,deny<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaDeny from all<br>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila&lt;/Location&gt;
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila</code></td></tr></table></blockquote>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>This works fine if the request is for
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<code>http://yoursite.example.com/dir/</code>. But what if you are on
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaa case-insensitive filesystem? Then your restriction could be easily
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilacircumvented by requesting
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<code>http://yoursite.example.com/DIR/</code>. The <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a> directive, in
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilacontrast, will apply to any content served from that location,
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaregardless of how it is called. (An exception is filesystem links.
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaThe same directory can be placed in more than one part of the
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilafilesystem using symbolic links. The <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a> directive will follow the symbolic
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilalink without resetting the pathname. Therefore, for the highest level
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilaof security, symbolic links should be disabled with the appropriate
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<a href="/mod/core.html#options" class="directive"><code class="directive">Options</code></a> directive.)</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>If you are, perhaps, thinking that none of this applies to you
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilabecause you use a case-sensitive filesystem, remember that there are
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilamany other ways to map multiple webspace locations to the same
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilafilesystem location. Therefore you should always use the filesystem
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilacontainers when you can. There is, however, one exception to this
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilarule. Putting configuration restrictions in a <code>&lt;Location
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila/&gt;</code> section is perfectly safe because this section will apply
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilato all requests regardless of the specific URL.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<h2><a name="virtualhost">Virtual Hosts</a></h2>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>The <a href="/mod/core.html#virtualhost" class="directive"><code class="directive">&lt;VirtualHost&gt;</code></a>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilacontainer encloses directives that apply to specific hosts.
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu HuovilaThis is useful when serving multiple hosts from the same machine
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilawith a different configuration for each. For more information,
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovilasee the <a href="vhosts/">Virtual Host Documentation</a>.</p>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<h2><a name="proxy">Proxy</a></h2>
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila
0605ff6f25783f7c69c1148f9f3a7bd4c34c098fTeemu Huovila<p>The <a href="/mod/proxy.html#proxy" class="directive"><code class="directive">&lt;Proxy&gt;</code></a>
container applies enclosed configuration directives only
to sites accessed through <code><a href="/mod/mod_proxy.html">mod_proxy</a></code>'s proxy server
that match the specified URL. For example, the following configuration
will prevent the proxy server from being used to access the
<code>cnn.com</code> website.</p>
<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
&lt;Proxy http://cnn.com/*&gt;<br>
Order allow,deny<br>
Deny from all<br>
&lt;/Proxy&gt;
</code></td></tr></table></blockquote>
<h2><a name="whatwhere">What Directives are Allowed?</a></h2>
<p>To find out what directives are allowed in what types of
configuration sections, check the <a href="mod/directive-dict.html#Context">Context</a> of the directive.
Everything that is allowed in
<a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a>
sections is also syntactically allowed in
<a href="/mod/core.html#directorymatch" class="directive"><code class="directive">&lt;DirectoryMatch&gt;</code></a>,
<a href="/mod/core.html#files" class="directive"><code class="directive">&lt;Files&gt;</code></a>,
<a href="/mod/core.html#filesmatch" class="directive"><code class="directive">&lt;FilesMatch&gt;</code></a>,
<a href="/mod/core.html#location" class="directive"><code class="directive">&lt;Location&gt;</code></a>,
<a href="/mod/core.html#locationmatch" class="directive"><code class="directive">&lt;LocationMatch&gt;</code></a>,
and
<a href="/mod/proxy.html#proxy" class="directive"><code class="directive">&lt;Proxy&gt;</code></a>
sections. There are some exceptions, however.</p>
<ul>
<li>The <a href="/mod/core.html#allowoverride" class="directive"><code class="directive">AllowOverride</code></a> directive
works only in <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a>
sections.</li>
<li>The <code>FollowSymLinks</code> and
<code>SymLinksIfOwnerMatch</code> <a href="/mod/core.html#options" class="directive"><code class="directive">Options</code></a> work only in <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a> sections or
<code>.htaccess</code> files.</li>
<li>The <a href="/mod/core.html#options" class="directive"><code class="directive">Options</code></a> directive cannot
be used in <a href="/mod/core.html#files" class="directive"><code class="directive">&lt;Files&gt;</code></a>
and <a href="/mod/core.html#filesmatch" class="directive"><code class="directive">&lt;FilesMatch&gt;</code></a>
sections.</li>
</ul>
<h2><a name="mergin">How the sections are merged</a></h2>
<p>The configuration sections are applied in a very particular order.
Since this can have important effects on how configuration directives
are interpreted, it is important to understand how this works.</p>
<p>The order of merging is:</p>
<ol>
<li> <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a> (except regular expressions)
and .htaccess done simultaneously (with .htaccess, if allowed,
overriding <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a>)</li>
<li><a href="/mod/core.html#directorymatch" class="directive"><code class="directive">&lt;DirectoryMatch&gt;</code></a>
(and <code>&lt;Directory ~&gt;</code>)</li>
<li><a href="/mod/core.html#files" class="directive"><code class="directive">&lt;Files&gt;</code></a> and <a href="/mod/core.html#filesmatch" class="directive"><code class="directive">&lt;FilesMatch&gt;</code></a> done
simultaneously</li>
<li><a href="/mod/core.html#location" class="directive"><code class="directive">&lt;Location&gt;</code></a>
and <a href="/mod/core.html#locationmatch" class="directive"><code class="directive">&lt;LocationMatch&gt;</code></a> done simultaneously</li>
</ol>
<p>Apart from <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a>, each group is processed in
the order that they appear in the configuration files. <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a> (group 1 above)
is processed in the order shortest directory component to longest.
So for example, <code>&lt;Directory /var/web/dir&gt;</code> will
be processed before <code>&lt;Directory
/var/web/dir/subdir&gt;</code>. If multiple <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a> sections apply
to the same directory they are processed in the configuration file
order. Configurations included via the <a href="/mod/core.html#include" class="directive"><code class="directive">Include</code></a> directive will be treated as if
they were inside the including file at the location of the
<a href="/mod/core.html#include" class="directive"><code class="directive">Include</code></a> directive.</p>
<p>Sections inside <a href="/mod/core.html#virtualhost" class="directive"><code class="directive">&lt;VirtualHost&gt;</code></a> sections
are applied <em>after</em> the corresponding sections outside
the virtual host definition. This allows virtual hosts to
override the main server configuration.</p>
<p>Later sections override earlier ones.</p>
<blockquote><table><tr><td bgcolor="#e0e5f5"><p align="center"><strong>Technical Note</strong></p>
There is actually a
<code>&lt;Location&gt;</code>/<code>&lt;LocationMatch&gt;</code>
sequence performed just before the name translation phase
(where <code>Aliases</code> and <code>DocumentRoots</code>
are used to map URLs to filenames). The results of this
sequence are completely thrown away after the translation has
completed.
</td></tr></table></blockquote>
<h3><a name="merge-examples">Some Examples</a></h3>
<p>Below is an artificial example to show the order of
merging. Assuming they all apply to the request, the directives in
this example will be applied in the order A &gt; B &gt; C &gt; D &gt;
E.</p>
<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
&lt;Location /&gt;<br>
E<br>
&lt;/Location&gt;<br>
<br>
&lt;Files f.html&gt;<br>
D<br>
&lt;/Files&gt;<br>
<br>
&lt;VirtualHost *&gt;<br>
&lt;Directory /a/b&gt;<br>
B<br>
&lt;/Directory&gt;<br>
&lt;/VirtualHost&gt;<br>
<br>
&lt;DirectoryMatch "^.*b$"&gt;<br>
C<br>
&lt;/DirectoryMatch&gt;<br>
<br>
&lt;Directory /a/b&gt;<br>
A<br>
&lt;/Directory&gt;<br>
<br>
</code></td></tr></table></blockquote>
<p>For a more concrete example, consider the following. Regardless of
any access restrictions placed in <a href="/mod/core.html#directory" class="directive"><code class="directive">&lt;Directory&gt;</code></a> sections, the <a href="/mod/core.html#location" class="directive"><code class="directive">&lt;Location&gt;</code></a> section will be
evaluated last and will allow unrestricted access to the server. In
other words, order of merging is important, so be careful!</p>
<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
&lt;Location /&gt;<br>
Order deny,allow<br>
Allow from all<br>
&lt;/Location&gt;<br>
<br>
# Woops! This &lt;Directory&gt; section will have no effect<br>
&lt;Directory /&gt;<br>
Order allow,deny<br>
Allow from all<br>
Deny from badguy.example.com<br>
&lt;/Directory&gt;
</code></td></tr></table></blockquote>
<hr></blockquote><h3 align="center">Apache HTTP Server Version 2.0</h3><a href="./"><img src="/images/index.gif" alt="Index"></a><a href="./"><img src="/images/home.gif" alt="Home"></a></body></html>