Differences between revisions 7 and 8
Revision 7 as of 2009-09-20 22:13:23
Size: 4597
Editor: localhost
Comment: converted to 1.6 markup
Revision 8 as of 2012-08-31 12:41:35
Size: 4600
Editor: Greg Martin
Comment:
Deletions are marked like this. Additions are marked like this.
Line 22: Line 22:
If no file from the DirectoryIndex directive can be located in the directory, then [[http://httpd.apache.org/docs/trunk/mod/mod_autoindex.html|mod_autoindex]] can generate a listing of the directory contents. This is turned on and off using the [[http://httpd.apache.org/docs/trunk/mod/core.html#options|Options]] directive. For example, to turn on directory listings for a particular directory, you can use If no file from the DirectoryIndex directive can be located in the directory, then [[http://httpd.apache.org/docs/trunk/mod/mod_autoindex.html|mod_autoindex]] can generate a listing of the directory contents. This is turned on and off using the [[http://httpd.apache.org/docs/trunk/mod/core.html#options|Options]] directive. For example, to turn on directory listings for a particular directory, you can use:
Line 30: Line 30:
To prevent directory listings (for security purposes, for example), you should remove the {{{Indexes}}} keyword from every Options directive in your configuration file. Or to prevent them only for a single directory, you can use To prevent directory listings (for security purposes, for example), you should remove the {{{Indexes}}} keyword from every Options directive in your configuration file. Or to prevent them only for a single directory, you can use:
Line 40: Line 40:
If you would like listings to be enabled, but you want to omit particular files, you can use the [[http://httpd.apache.org/docs/trunk/mod/mod_autoindex.html#indexignore|IndexIgnore]] directive. For example, to omit any filename starting with {{{tmp}}} and also the parent directory link (..), you could use If you would like listings to be enabled, but you want to omit particular files, you can use the [[http://httpd.apache.org/docs/trunk/mod/mod_autoindex.html#indexignore|IndexIgnore]] directive. For example, to omit any filename starting with {{{tmp}}} and also the parent directory link (..), you could use:

Directory Listing Configuration

Here we describe various types of things that the server can send when you request a directory rather than an individual file.

Trailing Slash Redirection

If you request a directory without including the trailing slash in its name (i.e. http://example.com/dir rather than http://example.com/dir/), then Apache must send a redirect to add the trailing slash to the URL. This is necessary so relative hyperlinks will work in the resulting file.

For this to work, Apache must know the name of the server so that it can send a redirect back to itself. Normally, when UseCanonicalName is set off, the name supplied by the client in the Host HTTP request header is used. If UseCanonicalName is on, then you need to assure that ServerName is set correctly in order for this redirect to work.

Directory Indexes

When a directory is requested, Apache may be configured to send a particular file within that directory automatically. This is configured with the DirectoryIndex directive. It can list one or more files that Apache should search for in the directory, with the first existing file being returned to the client. For example:

DirectoryIndex index.html index.htm index.php welcome.html

Directory Listings

If no file from the DirectoryIndex directive can be located in the directory, then mod_autoindex can generate a listing of the directory contents. This is turned on and off using the Options directive. For example, to turn on directory listings for a particular directory, you can use:

<Directory /usr/local/apache2/htdocs/listme>
  Options +Indexes
</Directory>

To prevent directory listings (for security purposes, for example), you should remove the Indexes keyword from every Options directive in your configuration file. Or to prevent them only for a single directory, you can use:

<Directory /usr/local/apache2/htdocs/dontlistme>
  Options -Indexes
</Directory>

Excluding Files

If you would like listings to be enabled, but you want to omit particular files, you can use the IndexIgnore directive. For example, to omit any filename starting with tmp and also the parent directory link (..), you could use:

IndexIgnore tmp* ..

Some files aren't listed

When a directory listing is produced, certain files will not be shown, by default. Files and directories that have access restrictions placed on them, either by password or by address, will not be shown in a directory listing.

If you want these files to be listed, you will need to set IndexOptions ShowForbidden in the directory block in question. The ShowForbidden setting is only available in 2.2 and later.

Headers and Footers

The directives HeaderName and ReadmeName configure a file to be included, respectively, above and below the file listing. If no path is given, Apache will look for these files in the directory being listed. For example:

HeaderName header.html
ReadmeName footer.html

A path starting in slash can be used if you want the same files included for all directories:

HeaderName /site/header.html
ReadmeName /site/footer.html

Styling the listing

The directory listing is highly configurable. The IndexOptions directive gives lots of choices for different configurations and the IndexStyleSheet directive allows a CSS stylesheet to be specified. A typical configuration might look like:

IndexOptions FancyIndexing HTMLTable
IndexStyleSheet /css/autoindex.css

Extended example

For a more complete example, including a configuration for the icons displayed with the files, see conf/extra/httpd-autoindex.conf as distributed with Apache httpd.

DirectoryListings (last edited 2012-08-31 12:41:35 by Greg Martin)