mod_dir.xml revision 650401e2cb916188d0e1a280dfa78dd67e24ce3b
0N/A<?xml version="1.0"?>
2362N/A<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
0N/A<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
0N/A<!-- $LastChangedRevision$ -->
0N/A
0N/A<!--
2362N/A Licensed to the Apache Software Foundation (ASF) under one or more
0N/A contributor license agreements. See the NOTICE file distributed with
2362N/A this work for additional information regarding copyright ownership.
0N/A The ASF licenses this file to You under the Apache License, Version 2.0
0N/A (the "License"); you may not use this file except in compliance with
0N/A the License. You may obtain a copy of the License at
0N/A
0N/A http://www.apache.org/licenses/LICENSE-2.0
0N/A
0N/A Unless required by applicable law or agreed to in writing, software
0N/A distributed under the License is distributed on an "AS IS" BASIS,
0N/A WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0N/A See the License for the specific language governing permissions and
0N/A limitations under the License.
2362N/A-->
2362N/A
2362N/A<modulesynopsis metafile="mod_dir.xml.meta">
0N/A<name>mod_dir</name>
0N/A<description>Provides for "trailing slash" redirects and
0N/A serving directory index files</description>
0N/A<status>Base</status>
0N/A<sourcefile>mod_dir.c</sourcefile>
0N/A<identifier>dir_module</identifier>
0N/A
0N/A<summary>
0N/A <p>The index of a directory can come from one of two sources:</p>
0N/A
0N/A <ul>
0N/A <li>A file written by the user, typically called
0N/A <code>index.html</code>. The <directive module="mod_dir"
0N/A >DirectoryIndex</directive> directive sets the
0N/A name of this file. This is controlled by
0N/A <module>mod_dir</module>.</li>
0N/A
0N/A <li>Otherwise, a listing generated by the server. This is
0N/A provided by <module>mod_autoindex</module>.</li>
0N/A </ul>
0N/A <p>The two functions are separated so that you can completely
0N/A remove (or replace) automatic index generation should you want
0N/A to.</p>
0N/A
0N/A <p>A "trailing slash" redirect is issued when the server
406N/A receives a request for a URL
406N/A <code>http://servername/foo/dirname</code> where
0N/A <code>dirname</code> is a directory. Directories require a
0N/A trailing slash, so <module>mod_dir</module> issues a redirect to
0N/A <code>http://servername/foo/dirname/</code>.</p>
0N/A</summary>
406N/A
406N/A<directivesynopsis>
0N/A<name>DirectoryIndex</name>
0N/A<description>List of resources to look for when the client requests
0N/Aa directory</description>
0N/A<syntax>DirectoryIndex
406N/A disabled | <var>local-url</var> [<var>local-url</var>] ...</syntax>
406N/A<default>DirectoryIndex index.html</default>
0N/A<contextlist><context>server config</context><context>virtual host</context>
0N/A<context>directory</context><context>.htaccess</context></contextlist>
0N/A<override>Indexes</override>
0N/A
406N/A<usage>
406N/A <p>The <directive>DirectoryIndex</directive> directive sets the
0N/A list of resources to look for, when the client requests an index
0N/A of the directory by specifying a / at the end of the directory
0N/A name. <var>Local-url</var> is the (%-encoded) URL of a document on
0N/A the server relative to the requested directory; it is usually the
0N/A name of a file in the directory. Several URLs may be given, in
0N/A which case the server will return the first one that it finds. If
0N/A none of the resources exist and the <code>Indexes</code> option is
0N/A set, the server will generate its own listing of the
0N/A directory.</p>
0N/A
0N/A <example><title>Example</title>
0N/A <highlight language="config">
0N/A DirectoryIndex index.html
0N/A </highlight>
0N/A </example>
0N/A
0N/A <p>then a request for <code>http://example.com/docs/</code> would
0N/A return <code>http://example.com/docs/index.html</code> if it
0N/A exists, or would list the directory if it did not.</p>
0N/A
0N/A <p>Note that the documents do not need to be relative to the
0N/A directory;</p>
0N/A
0N/A <highlight language="config">
0N/A DirectoryIndex index.html index.txt /cgi-bin/index.pl
0N/A </highlight>
0N/A
0N/A <p>would cause the CGI script <code>/cgi-bin/index.pl</code> to be
0N/A executed if neither <code>index.html</code> or <code>index.txt</code>
0N/A existed in a directory.</p>
0N/A
0N/A <p>A single argument of "disabled" prevents <module>mod_dir</module> from
0N/A searching for an index. An argument of "disabled" will be interpreted
0N/A literally if it has any arguments before or after it, even if they are "disabled"
0N/A as well.</p>
0N/A
0N/A <p><strong>Note:</strong> Multiple <directive>DirectoryIndex</directive>
0N/A directives within the <a href="/sections.html"><em>same context</em></a> will add
0N/A to the list of resources to look for rather than replace:
0N/A </p>
0N/A <highlight language="config">
0N/A# Example A: Set index.html as an index page, then add index.php to that list as well.
0N/A&lt;Directory /foo&gt;
1790N/A DirectoryIndex index.html
0N/A DirectoryIndex index.php
0N/A&lt;/Directory&gt;
0N/A
0N/A# Example B: This is identical to example A, except it's done with a single directive.
0N/A&lt;Directory /foo&gt;
0N/A DirectoryIndex index.html index.php
0N/A&lt;/Directory&gt;
0N/A
0N/A# Example C: To replace the list, you must explicitly reset it first:
0N/A# In this example, only index.php will remain as an index resource.
0N/A&lt;Directory /foo&gt;
406N/A DirectoryIndex index.html
406N/A DirectoryIndex disabled
406N/A DirectoryIndex index.php
0N/A&lt;/Directory&gt;
0N/A </highlight>
0N/A
0N/A</usage>
0N/A</directivesynopsis>
0N/A
0N/A<directivesynopsis>
0N/A<name>DirectoryIndexRedirect</name>
0N/A<description>Configures an external redirect for directory indexes.
0N/A</description>
0N/A<syntax>DirectoryIndexRedirect on | off | permanent | temp | seeother |
0N/A<var>3xx-code</var>
0N/A</syntax>
0N/A<default>DirectoryIndexRedirect off</default>
0N/A<contextlist><context>server config</context><context>virtual host</context>
0N/A<context>directory</context><context>.htaccess</context></contextlist>
0N/A<override>Indexes</override>
0N/A<compatibility>Available in version 2.3.14 and later</compatibility>
406N/A
406N/A<usage>
406N/A <p>By default, the <directive>DirectoryIndex</directive> is selected
0N/A and returned transparently to the client. <directive
0N/A >DirectoryIndexRedirect</directive> causes an external redirect
0N/A to instead be issued.</p>
0N/A
0N/A The argument can be :
0N/A <ul>
0N/A <li><code>on</code> : issues a 302 redirection to the index resource.</li>
0N/A <li><code>off</code> : does not issue a redirection. This is the legacy behaviour of mod_dir.</li>
0N/A <li><code>permanent</code> : issues a 301 (permanent) redirection to the index resource.</li>
0N/A <li><code>temp</code> : this has the same effect as <code>on</code></li>
0N/A <li><code>seeother</code> : issues a 303 redirection (also known as "See Other") to the index resource.</li>
0N/A <li><var>3xx-code</var> : issues a redirection marked by the chosen 3xx code.</li>
0N/A </ul>
0N/A
0N/A
0N/A <example><title>Example</title>
0N/A <highlight language="config">
0N/A DirectoryIndexRedirect on
0N/A </highlight>
0N/A </example>
0N/A
0N/A <p>A request for <code>http://example.com/docs/</code> would
0N/A return a temporary redirect to <code
0N/A >http://example.com/docs/index.html</code>
0N/A if it exists.</p>
0N/A
0N/A</usage>
0N/A</directivesynopsis>
0N/A
0N/A
0N/A<directivesynopsis>
0N/A<name>DirectorySlash</name>
0N/A<description>Toggle trailing slash redirects on or off</description>
0N/A<syntax>DirectorySlash On|Off</syntax>
0N/A<default>DirectorySlash On</default>
0N/A<contextlist><context>server config</context><context>virtual host</context>
1790N/A<context>directory</context><context>.htaccess</context></contextlist>
0N/A<override>Indexes</override>
0N/A
0N/A<usage>
0N/A <p>The <directive>DirectorySlash</directive> directive determines whether
0N/A <module>mod_dir</module> should fixup URLs pointing to a directory or
0N/A not.</p>
0N/A
0N/A <p>Typically if a user requests a resource without a trailing slash, which
0N/A points to a directory, <module>mod_dir</module> redirects him to the same
0N/A resource, but <em>with</em> trailing slash for some good reasons:</p>
0N/A
0N/A <ul>
0N/A <li>The user is finally requesting the canonical URL of the resource</li>
0N/A <li><module>mod_autoindex</module> works correctly. Since it doesn't emit
0N/A the path in the link, it would point to the wrong path.</li>
0N/A <li><directive module="mod_dir">DirectoryIndex</directive> will be evaluated
0N/A <em>only</em> for directories requested with trailing slash.</li>
0N/A <li>Relative URL references inside html pages will work correctly.</li>
0N/A </ul>
0N/A
0N/A <p>If you don't want this effect <em>and</em> the reasons above don't
0N/A apply to you, you can turn off the redirect as shown below. However,
0N/A be aware that there are possible security implications to doing
0N/A this.</p>
0N/A
0N/A <highlight language="config">
0N/A# see security warning below!
0N/A&lt;Location /some/path&gt;
0N/A DirectorySlash Off
0N/A SetHandler some-handler
0N/A&lt;/Location&gt;
0N/A </highlight>
0N/A
0N/A <note type="warning"><title>Security Warning</title>
0N/A <p>Turning off the trailing slash redirect may result in an information
0N/A disclosure. Consider a situation where <module>mod_autoindex</module> is
0N/A active (<code>Options +Indexes</code>) and <directive module="mod_dir"
0N/A >DirectoryIndex</directive> is set to a valid resource (say,
0N/A <code>index.html</code>) and there's no other special handler defined for
0N/A that URL. In this case a request with a trailing slash would show the
0N/A <code>index.html</code> file. <strong>But a request without trailing slash
0N/A would list the directory contents</strong>.</p>
0N/A </note>
0N/A <p>Also note that some browsers may erroneously change POST requests into GET
0N/A (thus discarding POST data) when a redirect is issued.</p>
0N/A</usage>
0N/A</directivesynopsis>
0N/A<directivesynopsis>
0N/A<name>FallbackResource</name>
0N/A<description>Define a default URL for requests that don't map to a file</description>
0N/A<syntax>FallbackResource disabled | <var>local-url</var></syntax>
0N/A<default>disabled - httpd will return 404 (Not Found)</default>
0N/A<contextlist><context>server config</context><context>virtual host</context>
0N/A<context>directory</context><context>.htaccess</context></contextlist>
0N/A<override>Indexes</override>
0N/A<usage>
0N/A <p>Use this to set a handler for any URL that doesn't map to anything
0N/A in your filesystem, and would otherwise return HTTP 404 (Not Found).
0N/A For example</p>
0N/A <highlight language="config">
0N/A FallbackResource /not-404.php
0N/A </highlight>
0N/A <p>will cause requests for non-existent files to be handled by
0N/A <code>not-404.php</code>, while requests for files that exist
0N/A are unaffected.</p>
0N/A <p>It is frequently desirable to have a single file or resource
0N/A handle all requests to a particular directory, except those requests
0N/A that correspond to an existing file or script. This is often
0N/A referred to as a 'front controller.'</p>
0N/A <p>In earlier versions of httpd, this effect typically required
0N/A <module>mod_rewrite</module>, and the use of the <code>-f</code> and
0N/A <code>-d</code> tests for file and directory existence. This now
1790N/A requires only one line of configuration.</p>
0N/A <highlight language="config">
0N/A FallbackResource /index.php
0N/A </highlight>
0N/A <p>Existing files, such as images, css files, and so on, will be
0N/A served normally.</p>
0N/A <p>Use the <code>disabled</code> argument to disable that feature
0N/A if inheritance from a parent directory is not desired.</p>
0N/A <p>In a sub-URI, such as <em>http://example.com/blog/</em> this
0N/A <em>sub-URI</em> has to be supplied as <var>local-url</var>:</p>
0N/A <highlight language="config">
0N/A&lt;Directory /web/example.com/htdocs/blog&gt;
0N/A FallbackResource /blog/index.php
0N/A&lt;/Directory&gt;
0N/A&lt;Directory /web/example.com/htdocs/blog/images&gt;
0N/A FallbackResource disabled
0N/A&lt;/Directory&gt;
0N/A </highlight>
0N/A</usage>
0N/A</directivesynopsis>
0N/A
0N/A</modulesynopsis>
0N/A