]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_dir.html.en
Update docco xforms
[apache] / docs / manual / mod / mod_dir.html.en
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!--
4         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
5               This file is generated from xml source: DO NOT EDIT
6         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
7       -->
8 <title>mod_dir - Apache HTTP Server</title>
9 <link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
10 <link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
11 <link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" />
12 <link href="../images/favicon.ico" rel="shortcut icon" /></head>
13 <body>
14 <div id="page-header">
15 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p>
16 <p class="apache">Apache HTTP Server Version 2.3</p>
17 <img alt="" src="../images/feather.gif" /></div>
18 <div class="up"><a href="./"><img title="&lt;-" alt="&lt;-" src="../images/left.gif" /></a></div>
19 <div id="path">
20 <a href="http://www.apache.org/">Apache</a> &gt; <a href="http://httpd.apache.org/">HTTP Server</a> &gt; <a href="http://httpd.apache.org/docs/">Documentation</a> &gt; <a href="../">Version 2.3</a> &gt; <a href="./">Modules</a></div>
21 <div id="page-content">
22 <div id="preamble"><h1>Apache Module mod_dir</h1>
23 <div class="toplang">
24 <p><span>Available Languages: </span><a href="../en/mod/mod_dir.html" title="English">&nbsp;en&nbsp;</a> |
25 <a href="../fr/mod/mod_dir.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
26 <a href="../ja/mod/mod_dir.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
27 <a href="../ko/mod/mod_dir.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
28 <a href="../tr/mod/mod_dir.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
29 </div>
30 <table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Provides for "trailing slash" redirects and
31     serving directory index files</td></tr>
32 <tr><th><a href="module-dict.html#Status">Status:</a></th><td>Base</td></tr>
33 <tr><th><a href="module-dict.html#ModuleIdentifier">Module Identifier:</a></th><td>dir_module</td></tr>
34 <tr><th><a href="module-dict.html#SourceFile">Source File:</a></th><td>mod_dir.c</td></tr></table>
35 <h3>Summary</h3>
36
37     <p>The index of a directory can come from one of two sources:</p>
38
39     <ul>
40       <li>A file written by the user, typically called
41       <code>index.html</code>. The <code class="directive"><a href="#directoryindex">DirectoryIndex</a></code> directive sets the
42       name of this file. This is controlled by
43       <code class="module"><a href="../mod/mod_dir.html">mod_dir</a></code>.</li>
44
45       <li>Otherwise, a listing generated by the server. This is
46       provided by <code class="module"><a href="../mod/mod_autoindex.html">mod_autoindex</a></code>.</li>
47     </ul>
48     <p>The two functions are separated so that you can completely
49     remove (or replace) automatic index generation should you want
50     to.</p> 
51
52     <p>A "trailing slash" redirect is issued when the server
53     receives a request for a URL
54     <code>http://servername/foo/dirname</code> where
55     <code>dirname</code> is a directory. Directories require a
56     trailing slash, so <code class="module"><a href="../mod/mod_dir.html">mod_dir</a></code> issues a redirect to
57     <code>http://servername/foo/dirname/</code>.</p>
58 </div>
59 <div id="quickview"><h3 class="directives">Directives</h3>
60 <ul id="toc">
61 <li><img alt="" src="../images/down.gif" /> <a href="#directoryindex">DirectoryIndex</a></li>
62 <li><img alt="" src="../images/down.gif" /> <a href="#directoryindexredirect">DirectoryIndexRedirect</a></li>
63 <li><img alt="" src="../images/down.gif" /> <a href="#directoryslash">DirectorySlash</a></li>
64 <li><img alt="" src="../images/down.gif" /> <a href="#fallbackresource">FallbackResource</a></li>
65 </ul>
66 </div>
67
68 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
69 <div class="directive-section"><h2><a name="DirectoryIndex" id="DirectoryIndex">DirectoryIndex</a> <a name="directoryindex" id="directoryindex">Directive</a></h2>
70 <table class="directive">
71 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>List of resources to look for when the client requests
72 a directory</td></tr>
73 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>DirectoryIndex
74     disabled | <var>local-url</var> [<var>local-url</var>] ...</code></td></tr>
75 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>DirectoryIndex index.html</code></td></tr>
76 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
77 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>Indexes</td></tr>
78 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
79 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_dir</td></tr>
80 </table>
81     <p>The <code class="directive">DirectoryIndex</code> directive sets the
82     list of resources to look for, when the client requests an index
83     of the directory by specifying a / at the end of the directory
84     name.  <var>Local-url</var> is the (%-encoded) URL of a document on
85     the server relative to the requested directory; it is usually the
86     name of a file in the directory. Several URLs may be given, in
87     which case the server will return the first one that it finds.  If
88     none of the resources exist and the <code>Indexes</code> option is
89     set, the server will generate its own listing of the
90     directory.</p>
91
92     <div class="example"><h3>Example</h3><p><code>
93       DirectoryIndex index.html
94     </code></p></div>
95
96     <p>then a request for <code>http://example.com/docs/</code> would
97     return <code>http://example.com/docs/index.html</code> if it
98     exists, or would list the directory if it did not.</p>
99
100     <p>Note that the documents do not need to be relative to the
101     directory;</p>
102
103     <div class="example"><p><code>
104       DirectoryIndex index.html index.txt  /cgi-bin/index.pl
105     </code></p></div>
106
107     <p>would cause the CGI script <code>/cgi-bin/index.pl</code> to be
108     executed if neither <code>index.html</code> or <code>index.txt</code>
109     existed in a directory.</p>
110
111     <p>A single argument of "disabled" prevents <code class="module"><a href="../mod/mod_dir.html">mod_dir</a></code> from 
112     searching for an index.  An argument of "disabled" will be interpeted
113     literally if it has any arguments before or after it, even if they are "disabled"
114     as well.</p>
115
116
117 </div>
118 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
119 <div class="directive-section"><h2><a name="DirectoryIndexRedirect" id="DirectoryIndexRedirect">DirectoryIndexRedirect</a> <a name="directoryindexredirect" id="directoryindexredirect">Directive</a></h2>
120 <table class="directive">
121 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Configures an external redirect for directory indexes.
122 </td></tr>
123 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>DirectoryIndexRedirect on | off | permanent | temp | seeother | 
124 <var>3xx-code</var>
125 </code></td></tr>
126 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>DirectoryIndexRedirect off</code></td></tr>
127 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
128 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>Indexes</td></tr>
129 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
130 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_dir</td></tr>
131 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>Available in version 2.3.14 and later</td></tr>
132 </table>
133     <p>By default, the <code class="directive">DirectoryIndex</code> is selected
134     and returned transparently to the client.  <code class="directive">DirectoryIndexRedirect</code> causes an external redirect
135     to instead be issued.</p>
136
137     <div class="example"><h3>Example</h3><p><code>
138       DirectoryIndexRedirect on
139     </code></p></div>
140
141     <p>A request for <code>http://example.com/docs/</code> would
142     return a temporary redirect to <code>http://example.com/docs/index.html</code> 
143     if it exists.</p>
144
145
146 </div>
147 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
148 <div class="directive-section"><h2><a name="DirectorySlash" id="DirectorySlash">DirectorySlash</a> <a name="directoryslash" id="directoryslash">Directive</a></h2>
149 <table class="directive">
150 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Toggle trailing slash redirects on or off</td></tr>
151 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>DirectorySlash On|Off</code></td></tr>
152 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>DirectorySlash On</code></td></tr>
153 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
154 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>Indexes</td></tr>
155 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
156 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_dir</td></tr>
157 <tr><th><a href="directive-dict.html#Compatibility">Compatibility:</a></th><td>Available in version 2.0.51 and later</td></tr>
158 </table>
159     <p>The <code class="directive">DirectorySlash</code> directive determines whether
160     <code class="module"><a href="../mod/mod_dir.html">mod_dir</a></code> should fixup URLs pointing to a directory or
161     not.</p>
162
163     <p>Typically if a user requests a resource without a trailing slash, which
164     points to a directory, <code class="module"><a href="../mod/mod_dir.html">mod_dir</a></code> redirects him to the same
165     resource, but <em>with</em> trailing slash for some good reasons:</p>
166
167     <ul>
168     <li>The user is finally requesting the canonical URL of the resource</li>
169     <li><code class="module"><a href="../mod/mod_autoindex.html">mod_autoindex</a></code> works correctly. Since it doesn't emit
170     the path in the link, it would point to the wrong path.</li>
171     <li><code class="directive"><a href="#directoryindex">DirectoryIndex</a></code> will be evaluated
172     <em>only</em> for directories requested with trailing slash.</li>
173     <li>Relative URL references inside html pages will work correctly.</li>
174     </ul>
175
176     <p>If you don't want this effect <em>and</em> the reasons above don't
177     apply to you, you can turn off the redirect as shown below. However,
178     be aware that there are possible security implications to doing
179     this.</p>
180
181     <div class="example"><p><code>
182         # see security warning below!<br />
183         &lt;Location /some/path&gt;<br />
184         <span class="indent">
185             DirectorySlash Off<br />
186             SetHandler some-handler<br />
187         </span>
188         &lt;/Location&gt;
189     </code></p></div>
190
191     <div class="warning"><h3>Security Warning</h3>
192     <p>Turning off the trailing slash redirect may result in an information
193     disclosure. Consider a situation where <code class="module"><a href="../mod/mod_autoindex.html">mod_autoindex</a></code> is
194     active (<code>Options +Indexes</code>) and <code class="directive"><a href="#directoryindex">DirectoryIndex</a></code> is set to a valid resource (say,
195     <code>index.html</code>) and there's no other special handler defined for
196     that URL. In this case a request with a trailing slash would show the
197     <code>index.html</code> file. <strong>But a request without trailing slash
198     would list the directory contents</strong>.</p>
199     </div>
200
201 </div>
202 <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div>
203 <div class="directive-section"><h2><a name="FallbackResource" id="FallbackResource">FallbackResource</a> <a name="fallbackresource" id="fallbackresource">Directive</a></h2>
204 <table class="directive">
205 <tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Define a default URL for requests that don't map to a file</td></tr>
206 <tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>FallbackResource <var>local-url</var></code></td></tr>
207 <tr><th><a href="directive-dict.html#Default">Default:</a></th><td><code>None - httpd will return 404 (Not Found)</code></td></tr>
208 <tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host, directory, .htaccess</td></tr>
209 <tr><th><a href="directive-dict.html#Override">Override:</a></th><td>Indexes</td></tr>
210 <tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Base</td></tr>
211 <tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_dir</td></tr>
212 </table>
213     <p>Use this to set a handler for any URL that doesn't map to anything
214     in your filesystem, and would otherwise return HTTP 404 (Not Found).
215     For example</p>
216     <div class="example"><p><code>
217         <code>FallbackResource /not-404.php</code>
218     </code></p></div>
219     <p>will cause requests for non-existent files to be handled by
220     <code>not-404.php</code>, while requests for files that exist
221     are unaffected.</p>
222     <p>It is frequently desirable to have a single file or resource
223     handle all requests to a particular directory, except those requests
224     that correspond to an existing file or script. This is often
225     referred to as a 'front controller.'</p>
226     <p>In earlier versions of httpd, this effect typically required
227     <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>, and the use of the <code>-f</code> and
228     <code>-d</code> tests for file and directory existence. This now
229     requires only one line of configuration.</p>
230     <div class="example"><p><code>
231         <code>FallbackResource /index.php</code>
232     </code></p></div>
233     <p>Existing files, such as images, css files, and so on, will be
234     served normally.</p>
235     <p>In a sub-URI, such as <em>http://example.com/blog/</em> this
236     <em>sub-URI</em> has to be supplied as <var>local-url</var>:</p>
237     <div class="example"><p><code>
238          <code>
239              &lt;Directory /web/example.com/htdocs/blog&gt;<br />
240              <span class="indent">
241                   FallbackResource /blog/index.php<br />
242              </span>
243              &lt;/Directory&gt;
244          </code>
245     </code></p></div>
246
247 </div>
248 </div>
249 <div class="bottomlang">
250 <p><span>Available Languages: </span><a href="../en/mod/mod_dir.html" title="English">&nbsp;en&nbsp;</a> |
251 <a href="../fr/mod/mod_dir.html" hreflang="fr" rel="alternate" title="Français">&nbsp;fr&nbsp;</a> |
252 <a href="../ja/mod/mod_dir.html" hreflang="ja" rel="alternate" title="Japanese">&nbsp;ja&nbsp;</a> |
253 <a href="../ko/mod/mod_dir.html" hreflang="ko" rel="alternate" title="Korean">&nbsp;ko&nbsp;</a> |
254 <a href="../tr/mod/mod_dir.html" hreflang="tr" rel="alternate" title="Türkçe">&nbsp;tr&nbsp;</a></p>
255 </div><div id="footer">
256 <p class="apache">Copyright 2011 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p>
257 <p class="menu"><a href="../mod/">Modules</a> | <a href="../mod/directives.html">Directives</a> | <a href="../faq/">FAQ</a> | <a href="../glossary.html">Glossary</a> | <a href="../sitemap.html">Sitemap</a></p></div>
258 </body></html>