2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
7 Licensed to the Apache Software Foundation (ASF) under one or more
8 contributor license agreements. See the NOTICE file distributed with
9 this work for additional information regarding copyright ownership.
10 The ASF licenses this file to You under the Apache License, Version 2.0
11 (the "License"); you may not use this file except in compliance with
12 the License. You may obtain a copy of the License at
14 http://www.apache.org/licenses/LICENSE-2.0
16 Unless required by applicable law or agreed to in writing, software
17 distributed under the License is distributed on an "AS IS" BASIS,
18 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 See the License for the specific language governing permissions and
20 limitations under the License.
23 <modulesynopsis metafile="mod_dir.xml.meta">
25 <description>Provides for "trailing slash" redirects and
26 serving directory index files</description>
28 <sourcefile>mod_dir.c</sourcefile>
29 <identifier>dir_module</identifier>
32 <p>The index of a directory can come from one of two sources:</p>
35 <li>A file written by the user, typically called
36 <code>index.html</code>. The <directive module="mod_dir"
37 >DirectoryIndex</directive> directive sets the
38 name of this file. This is controlled by
39 <module>mod_dir</module>.</li>
41 <li>Otherwise, a listing generated by the server. This is
42 provided by <module>mod_autoindex</module>.</li>
44 <p>The two functions are separated so that you can completely
45 remove (or replace) automatic index generation should you want
48 <p>A "trailing slash" redirect is issued when the server
49 receives a request for a URL
50 <code>http://servername/foo/dirname</code> where
51 <code>dirname</code> is a directory. Directories require a
52 trailing slash, so <module>mod_dir</module> issues a redirect to
53 <code>http://servername/foo/dirname/</code>.</p>
57 <name>DirectoryIndex</name>
58 <description>List of resources to look for when the client requests
59 a directory</description>
60 <syntax>DirectoryIndex
61 disabled | <var>local-url</var> [<var>local-url</var>] ...</syntax>
62 <default>DirectoryIndex index.html</default>
63 <contextlist><context>server config</context><context>virtual host</context>
64 <context>directory</context><context>.htaccess</context></contextlist>
65 <override>Indexes</override>
68 <p>The <directive>DirectoryIndex</directive> directive sets the
69 list of resources to look for, when the client requests an index
70 of the directory by specifying a / at the end of the directory
71 name. <var>Local-url</var> is the (%-encoded) URL of a document on
72 the server relative to the requested directory; it is usually the
73 name of a file in the directory. Several URLs may be given, in
74 which case the server will return the first one that it finds. If
75 none of the resources exist and the <code>Indexes</code> option is
76 set, the server will generate its own listing of the
79 <example><title>Example</title>
80 <highlight language="config">
81 DirectoryIndex index.html
85 <p>then a request for <code>http://example.com/docs/</code> would
86 return <code>http://example.com/docs/index.html</code> if it
87 exists, or would list the directory if it did not.</p>
89 <p>Note that the documents do not need to be relative to the
92 <highlight language="config">
93 DirectoryIndex index.html index.txt /cgi-bin/index.pl
96 <p>would cause the CGI script <code>/cgi-bin/index.pl</code> to be
97 executed if neither <code>index.html</code> or <code>index.txt</code>
98 existed in a directory.</p>
100 <p>A single argument of "disabled" prevents <module>mod_dir</module> from
101 searching for an index. An argument of "disabled" will be interpreted
102 literally if it has any arguments before or after it, even if they are "disabled"
105 <p><strong>Note:</strong> Multiple <directive>DirectoryIndex</directive>
106 directives within the <a href="../sections.html"><em>same context</em></a> will add
107 to the list of resources to look for rather than replace:
109 <highlight language="config">
110 # Example A: Set index.html as an index page, then add index.php to that list as well.
111 <Directory /foo>
112 DirectoryIndex index.html
113 DirectoryIndex index.php
116 # Example B: This is identical to example A, except it's done with a single directive.
117 <Directory /foo>
118 DirectoryIndex index.html index.php
121 # Example C: To replace the list, you must explicitly reset it first:
122 # In this example, only index.php will remain as an index resource.
123 <Directory /foo>
124 DirectoryIndex index.html
125 DirectoryIndex disabled
126 DirectoryIndex index.php
134 <name>DirectoryIndexRedirect</name>
135 <description>Configures an external redirect for directory indexes.
137 <syntax>DirectoryIndexRedirect on | off | permanent | temp | seeother |
140 <default>DirectoryIndexRedirect off</default>
141 <contextlist><context>server config</context><context>virtual host</context>
142 <context>directory</context><context>.htaccess</context></contextlist>
143 <override>Indexes</override>
144 <compatibility>Available in version 2.3.14 and later</compatibility>
147 <p>By default, the <directive>DirectoryIndex</directive> is selected
148 and returned transparently to the client. <directive
149 >DirectoryIndexRedirect</directive> causes an external redirect
150 to instead be issued.</p>
152 <p> The argument can be : </p>
154 <li><code>on</code> : issues a 302 redirection to the index resource.</li>
155 <li><code>off</code> : does not issue a redirection. This is the legacy behaviour of mod_dir.</li>
156 <li><code>permanent</code> : issues a 301 (permanent) redirection to the index resource.</li>
157 <li><code>temp</code> : this has the same effect as <code>on</code></li>
158 <li><code>seeother</code> : issues a 303 redirection (also known as "See Other") to the index resource.</li>
159 <li><var>3xx-code</var> : issues a redirection marked by the chosen 3xx code.</li>
163 <example><title>Example</title>
164 <highlight language="config">
165 DirectoryIndexRedirect on
169 <p>A request for <code>http://example.com/docs/</code> would
170 return a temporary redirect to <code
171 >http://example.com/docs/index.html</code>
179 <name>DirectorySlash</name>
180 <description>Toggle trailing slash redirects on or off</description>
181 <syntax>DirectorySlash On|Off</syntax>
182 <default>DirectorySlash On</default>
183 <contextlist><context>server config</context><context>virtual host</context>
184 <context>directory</context><context>.htaccess</context></contextlist>
185 <override>Indexes</override>
188 <p>The <directive>DirectorySlash</directive> directive determines whether
189 <module>mod_dir</module> should fixup URLs pointing to a directory or
192 <p>Typically if a user requests a resource without a trailing slash, which
193 points to a directory, <module>mod_dir</module> redirects him to the same
194 resource, but <em>with</em> trailing slash for some good reasons:</p>
197 <li>The user is finally requesting the canonical URL of the resource</li>
198 <li><module>mod_autoindex</module> works correctly. Since it doesn't emit
199 the path in the link, it would point to the wrong path.</li>
200 <li><directive module="mod_dir">DirectoryIndex</directive> will be evaluated
201 <em>only</em> for directories requested with trailing slash.</li>
202 <li>Relative URL references inside html pages will work correctly.</li>
205 <p>If you don't want this effect <em>and</em> the reasons above don't
206 apply to you, you can turn off the redirect as shown below. However,
207 be aware that there are possible security implications to doing
210 <highlight language="config">
211 # see security warning below!
212 <Location /some/path>
214 SetHandler some-handler
218 <note type="warning"><title>Security Warning</title>
219 <p>Turning off the trailing slash redirect may result in an information
220 disclosure. Consider a situation where <module>mod_autoindex</module> is
221 active (<code>Options +Indexes</code>) and <directive module="mod_dir"
222 >DirectoryIndex</directive> is set to a valid resource (say,
223 <code>index.html</code>) and there's no other special handler defined for
224 that URL. In this case a request with a trailing slash would show the
225 <code>index.html</code> file. <strong>But a request without trailing slash
226 would list the directory contents</strong>.</p>
228 <p>Also note that some browsers may erroneously change POST requests into GET
229 (thus discarding POST data) when a redirect is issued.</p>
233 <name>FallbackResource</name>
234 <description>Define a default URL for requests that don't map to a file</description>
235 <syntax>FallbackResource disabled | <var>local-url</var></syntax>
236 <default>disabled - httpd will return 404 (Not Found)</default>
237 <contextlist><context>server config</context><context>virtual host</context>
238 <context>directory</context><context>.htaccess</context></contextlist>
239 <override>Indexes</override>
241 <p>Use this to set a handler for any URL that doesn't map to anything
242 in your filesystem, and would otherwise return HTTP 404 (Not Found).
244 <highlight language="config">
245 FallbackResource /not-404.php
247 <p>will cause requests for non-existent files to be handled by
248 <code>not-404.php</code>, while requests for files that exist
250 <p>It is frequently desirable to have a single file or resource
251 handle all requests to a particular directory, except those requests
252 that correspond to an existing file or script. This is often
253 referred to as a 'front controller.'</p>
254 <p>In earlier versions of httpd, this effect typically required
255 <module>mod_rewrite</module>, and the use of the <code>-f</code> and
256 <code>-d</code> tests for file and directory existence. This now
257 requires only one line of configuration.</p>
258 <highlight language="config">
259 FallbackResource /index.php
261 <p>Existing files, such as images, css files, and so on, will be
263 <p>Use the <code>disabled</code> argument to disable that feature
264 if inheritance from a parent directory is not desired.</p>
265 <p>In a sub-URI, such as <em>http://example.com/blog/</em> this
266 <em>sub-URI</em> has to be supplied as <var>local-url</var>:</p>
267 <highlight language="config">
268 <Directory /web/example.com/htdocs/blog>
269 FallbackResource /blog/index.php
271 <Directory /web/example.com/htdocs/blog/images>
272 FallbackResource disabled