]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_dir.xml
The local uri part is *always* the whole Request_URI. Including the leading /.
[apache] / docs / manual / mod / mod_dir.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <!-- $LastChangedRevision$ -->
5
6 <!--
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
13
14      http://www.apache.org/licenses/LICENSE-2.0
15
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.
21 -->
22
23 <modulesynopsis metafile="mod_dir.xml.meta">
24 <name>mod_dir</name>
25 <description>Provides for "trailing slash" redirects and
26     serving directory index files</description>
27 <status>Base</status>
28 <sourcefile>mod_dir.c</sourcefile>
29 <identifier>dir_module</identifier>
30
31 <summary>
32     <p>The index of a directory can come from one of two sources:</p>
33
34     <ul>
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>
40
41       <li>Otherwise, a listing generated by the server. This is
42       provided by <module>mod_autoindex</module>.</li>
43     </ul>
44     <p>The two functions are separated so that you can completely
45     remove (or replace) automatic index generation should you want
46     to.</p> 
47
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>
54 </summary>
55
56 <directivesynopsis>
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>
66
67 <usage>
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
77     directory.</p>
78
79     <example><title>Example</title>
80       DirectoryIndex index.html
81     </example>
82
83     <p>then a request for <code>http://myserver/docs/</code> would
84     return <code>http://myserver/docs/index.html</code> if it
85     exists, or would list the directory if it did not.</p>
86
87     <p>Note that the documents do not need to be relative to the
88     directory;</p>
89
90     <example>
91       DirectoryIndex index.html index.txt  /cgi-bin/index.pl
92     </example>
93
94     <p>would cause the CGI script <code>/cgi-bin/index.pl</code> to be
95     executed if neither <code>index.html</code> or <code>index.txt</code>
96     existed in a directory.</p>
97
98     <p>A single argument of "disabled" prevents <module>mod_dir</module> from 
99     searching for an index.  An argument of "disabled" will be interpeted
100     literally if it has any arguments before or after it, even if they are "disabled"
101     as well.</p>
102
103 </usage>
104 </directivesynopsis>
105
106 <directivesynopsis>
107 <name>DirectorySlash</name>
108 <description>Toggle trailing slash redirects on or off</description>
109 <syntax>DirectorySlash On|Off</syntax>
110 <default>DirectorySlash On</default>
111 <contextlist><context>server config</context><context>virtual host</context>
112 <context>directory</context><context>.htaccess</context></contextlist>
113 <override>Indexes</override>
114 <compatibility>Available in version 2.0.51 and later</compatibility>
115
116 <usage>
117     <p>The <directive>DirectorySlash</directive> directive determines, whether
118     <module>mod_dir</module> should fixup URLs pointing to a directory or
119     not.</p>
120
121     <p>Typically if a user requests a resource without a trailing slash, which
122     points to a directory, <module>mod_dir</module> redirects him to the same
123     resource, but <em>with</em> trailing slash for some good reasons:</p>
124
125     <ul>
126     <li>The user is finally requesting the canonical URL of the resource</li>
127     <li><module>mod_autoindex</module> works correctly. Since it doesn't emit
128     the path in the link, it would point to the wrong path.</li>
129     <li><directive module="mod_dir">DirectoryIndex</directive> will be evaluated
130     <em>only</em> for directories requested with trailing slash.</li>
131     <li>Relative URL references inside html pages will work correctly.</li>
132     </ul>
133
134     <p>Well, if you don't want this effect <em>and</em> the reasons above don't
135     apply to you, you can turn off the redirect with:</p>
136
137     <example>
138         # see security warning below!<br />
139         &lt;Location /some/path&gt;<br />
140         <indent>
141             DirectorySlash Off<br />
142             SetHandler some-handler<br />
143         </indent>
144         &lt;/Location&gt;
145     </example>
146
147     <note type="warning"><title>Security Warning</title>
148     <p>Turning off the trailing slash redirect may result in an information
149     disclosure. Consider a situation where <module>mod_autoindex</module> is
150     active (<code>Options +Indexes</code>) and <directive module="mod_dir"
151     >DirectoryIndex</directive> is set to a valid resource (say,
152     <code>index.html</code>) and there's no other special handler defined for
153     that URL. In this case a request with a trailing slash would show the
154     <code>index.html</code> file. <strong>But a request without trailing slash
155     would list the directory contents</strong>.</p>
156     </note>
157 </usage>
158 </directivesynopsis>
159 <directivesynopsis>
160 <name>FallbackResource</name>
161 <description>Define a default URL for requests that don't map to a file</description>
162 <syntax>FallbackResource <var>local-url</var></syntax>
163 <default>None - httpd will return 404 (Not Found)</default>
164 <contextlist><context>server config</context><context>virtual host</context>
165 <context>directory</context><context>.htaccess</context></contextlist>
166 <override>Indexes</override>
167 <usage>
168     <p>Use this to set a handler for any URL that doesn't map to anything
169     in your filesystem, and would otherwise return HTTP 404 (Not Found).
170     For example</p>
171     <example>
172         <code>FallbackResource /not-404.php</code>
173     </example>
174     <p>will cause requests for non-existent files to be handled by
175     <code>not-404.php</code>, while requests for files that exist
176     are unaffected.</p>
177     <p>It is frequently desirable to have a single file or resource
178     handle all requests to a particular directory, except those requests
179     that correspond to an existing file or script. This is often
180     referred to as a 'front controller.'</p>
181     <p>In earlier versions of httpd, this effect typically required
182     <module>mod_rewrite</module>, and the use of the <code>-f</code> and
183     <code>-d</code> tests for file and directory existence. This now
184     requires only one line of configuration.</p>
185     <example>
186         <code>FallbackResource /index.php</code>
187     </example>
188     <p>Existing files, such as images, css files, and so on, will be
189     served normally.</p>
190     <p>In a sub-URI, such as <em>http://example.com/blog/</em> this
191     <em>sub-URI</em> has to be supplied as <var>local-url</var>:</p>
192     <example>
193          <code>
194              &lt;Directory /web/example.com/htdocs/blog&gt;<br />
195              <indent>
196                   FallbackResource /blog/index.php<br />
197              </indent>
198              &lt;/Directory&gt;
199          </code>
200     </example>
201 </usage>
202 </directivesynopsis>
203
204 </modulesynopsis>