mod_dir

Overview

mod_dir module cares about "trailing slash" redirects and directory index files handling.

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

  • a file written by the user, typically called index.html . The DirectoryIndex directive sets the name of this file. This is controlled by mod_dir.
  • a listing generated by the server.

The two functions are separated so that you can completely remove/replace automatic index generation if needed.

A "trailing slash" redirect takes place when the server is requested e.g. http://servername/foo/dirname , where dirname is a directory. As directories require a trailing slash, mod_dir forces redirect to http://servername/foo/dirname / .

Quick start

Here are the lines needed to force Ape account for trailing slash redirects and index files:

DirectoryIndex index.html index.asp index.php
DirectorySlash On

Directives

Name Context Description
DirectoryIndex S V D .h specifies the list of resources to look for when request to directory comes in the form of http://servername/foo/dirname /
DirectorySlash S V D .h enables/disables trailing slash redirects

DirectoryIndex

DirectoryIndex directive specifies the list of resources to look for when request to directory comes in the form of http://servername/foo/dirname / (directory name with the trailing slash).

Syntax

DirectoryIndex local-url [local-url] ...

Description

  • Local-url is the URL of the document on the server relative to the requested directory; usually it's the name of the file in the directory. You may list several URLs, in such case the first found will be returned in response. If none of the resources exist and the Indexes option is set, the server will generate its own listing of the directory.

Default

DirectoryIndex index.html

Example

DirectoryIndex index.asp

With the above line in place the request for http://myserver/dir/ will return http://myserver/dir/index.html if it exists, and will list the directory if it doesn't.

Note that the documents DO NOT need to be relative to the directory:

DirectoryIndex index.html index.txt /cgi-bin/index.pl

This code will trigger CGI script /cgi-bin/index.pl if neither index.html nor index.txt are found inside the directory.

DirectorySlash

DirectorySlash directive defines whether the trailing slash redirect upon directory request occurs or not.

Syntax

DirectorySlash On|Off

Default

DirectorySlash On

By default ( DirectorySlash On ) when the user requests a resource (which is a directory) without trailing slash, mod_dir forces redirect to this same resource but with trailing slash. In case you don't want this to happen, you may disable trailing slash redirects for the desired context:

Example

<Location /some/path>
  DirectorySlash Off
</Location>