Apache Module mod_dir
Example A: Set index.html as an index page, then add index.php to that list as well. DirectoryIndex index.html DirectoryIndex index.php
Example B: This is identical to example A, except it's done with a single directive. DirectoryIndex index.html index.php
Example C: To replace the list, you must explicitly reset it first:
In this example, only index.php will remain as an index resource. DirectoryIndex index.html DirectoryIndex disabled DirectoryIndex index.php
see security warning below! DirectorySlash Off SetHandler some-handler
The index of a directory can come from one of two sources:
directive sets the name of this file. This is controlled by mod_dir
.The two functions are separated so that you can completely remove (or replace) automatic index generation should you want to.
A "trailing slash" redirect is issued when the server receives a request for a URL http://servername/foo/dirname
is a directory. Directories require a trailing slash, so
issues a redirect to mod_dirhttp://servername/foo/dirname/
In releases prior to 2.4, this module did not take any action if any other handler was configured for a URL. This allows directory indexes to be served even when a SetHandler
directive is specified for an entire directory, but it can also result in some conflicts with modules such as mod_rewrite
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. Local-url 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 Indexes
option is set, the server will generate its own listing of the directory.
Note that the documents do not need to be relative to the directory;
DirectoryIndex index.html index.txt /cgi-bin/index.pl
would cause the CGI script /cgi-bin/index.pl
to be executed if neither index.html
A single argument of "disabled" prevents
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.mod_dir
directives within the same context will add to the list of resources to look for rather than replace:
DirectoryIndexRedirect on | off | permanent | temp | seeother | 3xx-code
: does not issue a redirection. This is the legacy behaviour of mod_dir.permanent
would return a temporary redirect to http://example.com/docs/index.html
Typically if a user requests a resource without a trailing slash, which points to a directory,
redirects him to the same resource, but mod_dirwith trailing slash for some good reasons:
works correctly. Since it doesn't emit the path in the link, it would point to the wrong path.DirectoryIndex
will be evaluated If you don't want this effect and 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.
Turning off the trailing slash redirect may result in an information disclosure. Consider a situation where
is active (mod_autoindexOptions +Indexes
is set to a valid resource (say, DirectoryIndexindex.html
) and there's no other special handler defined for that URL. In this case a request with a trailing slash would show the index.html
Also note that some browsers may erroneously change POST requests into GET (thus discarding POST data) when a redirect is issued.
will cause requests for non-existent files to be handled by not-404.php
, while requests for files that exist are unaffected.
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.'
In earlier versions of httpd, this effect typically required
tests for file and directory existence. This now requires only one line of configuration.
argument to disable that feature if inheritance from a parent directory is not desired.
In a sub-URI, such as http://example.com/blog/ this sub-URI has to be supplied as local-url:
Modules | Directives | FAQ | Glossary | Sitemap
Apache HTTP Server Version 2.4
Apache Module mod_dir
Available Languages: en | fr | ja | ko | tr
DirectoryCheckHandler Directive
The DirectoryCheckHandler directive determines whether mod_dir should check for directory indexes or add trailing slashes when some other handler has been configured for the current URL. Handlers can be set by directives such as SetHandler or by other modules, such as mod_rewrite during per-director
DirectoryIndex Directive
The DirectoryIndex 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. Local-url is the (%-encoded) URL of a document on the server relative to the requested directory; it is usually the name of a fi
DirectoryIndexRedirect Directive
By default, the DirectoryIndex is selected and returned transparently to the client. DirectoryIndexRedirect causes an external redirect to instead be issued.
DirectorySlash Directive
The DirectorySlash directive determines whether mod_dir should fixup URLs pointing to a directory or not.
FallbackResource Directive
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