<-
Apache > HTTP Server > Documentation > Version 2.4 > Modules

Apache Module mod_dir

Available Languages:  en  |  fr  |  ja  |  ko  |  tr 

Description:Provides for "trailing slash" redirects and serving directory index files
Status:Base
Module Identifier:dir_module
Source File:mod_dir.c

Summary

The index of a directory can come from one of two sources:

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 where dirname is a directory. Directories require a trailing slash, so mod_dir issues a redirect to http://servername/foo/dirname/.

Support Apache!

Directives

Bugfix checklist

See also

top

DirectoryCheckHandler Directive

Description:Toggle how this module responds when another handler is configured
Syntax:DirectoryCheckHandler On|Off
Default:DirectoryCheckHandler Off
Context:server config, virtual host, directory, .htaccess
Override:Indexes
Status:Base
Module:mod_dir
Compatibility:Available in 2.4.8 and later. Releases prior to 2.4 implicitly act as if "DirectoryCheckHandler ON" was specified.

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-directory substitutions.

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.

top

DirectoryIndex Directive

Description:List of resources to look for when the client requests a directory
Syntax:DirectoryIndex disabled | local-url [local-url] ...
Default:DirectoryIndex index.html
Context:server config, virtual host, directory, .htaccess
Override:Indexes
Status:Base
Module:mod_dir

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 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.

Example

DirectoryIndex index.html

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

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 or index.txt existed in a directory.

A single argument of "disabled" prevents mod_dir 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.

Note: Multiple DirectoryIndex directives within the same context will add to the list of resources to look for rather than replace:

# Example A: Set index.html as an index page, then add index.php to that list as well.
<Directory "/foo">
    DirectoryIndex index.html
    DirectoryIndex index.php
</Directory>

# Example B: This is identical to example A, except it's done with a single directive.
<Directory "/foo">
    DirectoryIndex index.html index.php
</Directory>

# Example C: To replace the list, you must explicitly reset it first:
# In this example, only index.php will remain as an index resource.
<Directory "/foo">
    DirectoryIndex index.html
    DirectoryIndex disabled
    DirectoryIndex index.php
</Directory>
top

DirectoryIndexRedirect Directive

Description:Configures an external redirect for directory indexes.
Syntax:DirectoryIndexRedirect on | off | permanent | temp | seeother | 3xx-code
Default:DirectoryIndexRedirect off
Context:server config, virtual host, directory, .htaccess
Override:Indexes
Status:Base
Module:mod_dir
Compatibility:Available in version 2.3.14 and later

By default, the DirectoryIndex is selected and returned transparently to the client. DirectoryIndexRedirect causes an external redirect to instead be issued.

The argument can be:

Example

DirectoryIndexRedirect on

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

top

DirectorySlash Directive

Description:Toggle trailing slash redirects on or off
Syntax:DirectorySlash On|Off
Default:DirectorySlash On
Context:server config, virtual host, directory, .htaccess
Override:Indexes
Status:Base
Module:mod_dir

The DirectorySlash directive determines whether mod_dir should fixup URLs pointing to a directory or not.

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