summaryrefslogtreecommitdiffstats
path: root/docs/manual/mod/mod_dir.xml
blob: 4762cabf4268bfc54f166f0208811ece235e8aa8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?xml version="1.0"?>
<!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
<?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
<!-- $LastChangedRevision$ -->

<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<modulesynopsis metafile="mod_dir.xml.meta">
<name>mod_dir</name>
<description>Provides for "trailing slash" redirects and
    serving directory index files</description>
<status>Base</status>
<sourcefile>mod_dir.c</sourcefile>
<identifier>dir_module</identifier>

<summary>
    <p>The index of a directory can come from one of two sources:</p>

    <ul>
      <li>A file written by the user, typically called
      <code>index.html</code>. The <directive module="mod_dir"
      >DirectoryIndex</directive> directive sets the
      name of this file. This is controlled by
      <module>mod_dir</module>.</li>

      <li>Otherwise, a listing generated by the server. This is
      provided by <module>mod_autoindex</module>.</li>
    </ul>
    <p>The two functions are separated so that you can completely
    remove (or replace) automatic index generation should you want
    to.</p>

    <p>A "trailing slash" redirect is issued when the server
    receives a request for a URL
    <code>http://servername/foo/dirname</code> where
    <code>dirname</code> is a directory. Directories require a
    trailing slash, so <module>mod_dir</module> issues a redirect to
    <code>http://servername/foo/dirname/</code>.</p>
</summary>

<directivesynopsis>
<name>DirectoryIndex</name>
<description>List of resources to look for when the client requests
a directory</description>
<syntax>DirectoryIndex
    disabled | <var>local-url</var> [<var>local-url</var>] ...</syntax>
<default>DirectoryIndex index.html</default>
<contextlist><context>server config</context><context>virtual host</context>
<context>directory</context><context>.htaccess</context></contextlist>
<override>Indexes</override>

<usage>
    <p>The <directive>DirectoryIndex</directive> directive sets the
    list of resources to look for, when the client requests an index
    of the directory by specifying a / at the end of the directory
    name.  <var>Local-url</var> is the (%-encoded) URL of a document on
    the server relative to the requested directory; it is usually the
    name of a file in the directory. Several URLs may be given, in
    which case the server will return the first one that it finds.  If
    none of the resources exist and the <code>Indexes</code> option is
    set, the server will generate its own listing of the
    directory.</p>

    <example><title>Example</title>
      DirectoryIndex index.html
    </example>

    <p>then a request for <code>http://example.com/docs/</code> would
    return <code>http://example.com/docs/index.html</code> if it
    exists, or would list the directory if it did not.</p>

    <p>Note that the documents do not need to be relative to the
    directory;</p>

    <example>
      DirectoryIndex index.html index.txt  /cgi-bin/index.pl
    </example>

    <p>would cause the CGI script <code>/cgi-bin/index.pl</code> to be
    executed if neither <code>index.html</code> or <code>index.txt</code>
    existed in a directory.</p>

    <p>A single argument of "disabled" prevents <module>mod_dir</module> from
    searching for an index.  An argument of "disabled" will be interpreted
    literally if it has any arguments before or after it, even if they are "disabled"
    as well.</p>

</usage>
</directivesynopsis>

<directivesynopsis>
<name>DirectoryIndexRedirect</name>
<description>Configures an external redirect for directory indexes.
</description>
<syntax>DirectoryIndexRedirect on | off | permanent | temp | seeother |
<var>3xx-code</var>
</syntax>
<default>DirectoryIndexRedirect off</default>
<contextlist><context>server config</context><context>virtual host</context>
<context>directory</context><context>.htaccess</context></contextlist>
<override>Indexes</override>
<compatibility>Available in version 2.3.14 and later</compatibility>

<usage>
    <p>By default, the <directive>DirectoryIndex</directive> is selected
    and returned transparently to the client.  <directive
    >DirectoryIndexRedirect</directive> causes an external redirect
    to instead be issued.</p>

    <example><title>Example</title>
      DirectoryIndexRedirect on
    </example>

    <p>A request for <code>http://example.com/docs/</code> would
    return a temporary redirect to <code
    >http://example.com/docs/index.html</code>
    if it exists.</p>

</usage>
</directivesynopsis>


<directivesynopsis>
<name>DirectorySlash</name>
<description>Toggle trailing slash redirects on or off</description>
<syntax>DirectorySlash On|Off</syntax>
<default>DirectorySlash On</default>
<contextlist><context>server config</context><context>virtual host</context>
<context>directory</context><context>.htaccess</context></contextlist>
<override>Indexes</override>
<compatibility>Available in version 2.0.51 and later</compatibility>

<usage>
    <p>The <directive>DirectorySlash</directive> directive determines whether
    <module>mod_dir</module> should fixup URLs pointing to a directory or
    not.</p>

    <p>Typically if a user requests a resource without a trailing slash, which
    points to a directory, <module>mod_dir</module> redirects him to the same
    resource, but <em>with</em> trailing slash for some good reasons:</p>

    <ul>
    <li>The user is finally requesting the canonical URL of the resource</li>
    <li><module>mod_autoindex</module> works correctly. Since it doesn't emit
    the path in the link, it would point to the wrong path.</li>
    <li><directive module="mod_dir">DirectoryIndex</directive> will be evaluated
    <em>only</em> for directories requested with trailing slash.</li>
    <li>Relative URL references inside html pages will work correctly.</li>
    </ul>

    <p>If you don't want this effect <em>and</em> the reasons above don't
    apply to you, you can turn off the redirect as shown below. However,
    be aware that there are possible security implications to doing
    this.</p>

    <example>
        # see security warning below!<br />
        &lt;Location /some/path&gt;<br />
        <indent>
            DirectorySlash Off<br />
            SetHandler some-handler<br />
        </indent>
        &lt;/Location&gt;
    </example>

    <note type="warning"><title>Security Warning</title>
    <p>Turning off the trailing slash redirect may result in an information
    disclosure. Consider a situation where <module>mod_autoindex</module> is
    active (<code>Options +Indexes</code>) and <directive module="mod_dir"
    >DirectoryIndex</directive> is set to a valid resource (say,
    <code>index.html</code>) and there's no other special handler defined for
    that URL. In this case a request with a trailing slash would show the
    <code>index.html</code> file. <strong>But a request without trailing slash
    would list the directory contents</strong>.</p>
    </note>
	<p>Also note that some browsers may erroneously change POST requests into GET 
	(thus discarding POST data) when a redirect is issued.</p>
</usage>
</directivesynopsis>
<directivesynopsis>
<name>FallbackResource</name>
<description>Define a default URL for requests that don't map to a file</description>
<syntax>FallbackResource <var>local-url</var></syntax>
<default>None - httpd will return 404 (Not Found)</default>
<contextlist><context>server config</context><context>virtual host</context>
<context>directory</context><context>.htaccess</context></contextlist>
<override>Indexes</override>
<usage>
    <p>Use this to set a handler for any URL that doesn't map to anything
    in your filesystem, and would otherwise return HTTP 404 (Not Found).
    For example</p>
    <example>
        <code>FallbackResource /not-404.php</code>
    </example>
    <p>will cause requests for non-existent files to be handled by
    <code>not-404.php</code>, while requests for files that exist
    are unaffected.</p>
    <p>It is frequently desirable to have a single file or resource
    handle all requests to a particular directory, except those requests
    that correspond to an existing file or script. This is often
    referred to as a 'front controller.'</p>
    <p>In earlier versions of httpd, this effect typically required
    <module>mod_rewrite</module>, and the use of the <code>-f</code> and
    <code>-d</code> tests for file and directory existence. This now
    requires only one line of configuration.</p>
    <example>
        <code>FallbackResource /index.php</code>
    </example>
    <p>Existing files, such as images, css files, and so on, will be
    served normally.</p>
    <p>In a sub-URI, such as <em>http://example.com/blog/</em> this
    <em>sub-URI</em> has to be supplied as <var>local-url</var>:</p>
    <example>
         <code>
             &lt;Directory /web/example.com/htdocs/blog&gt;<br />
	     <indent>
                  FallbackResource /blog/index.php<br />
             </indent>
             &lt;/Directory&gt;
         </code>
    </example>
</usage>
</directivesynopsis>

</modulesynopsis>