O'Reilly logo

Apache Cookbook, 2nd Edition by Ken Coar, Rich Bowen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12. Directory Listings

The default Apache HTTP Server package includes a module, mod_autoindex, for displaying a directory listing as a Web page. The default display is simple and informative, but the module provides all sorts of controls to let you tweak and customize the output.

12.1. Generating Directory/Folder Listings

Problem

You want to see a directory listing when a directory is requested.

Solution

Turn on Options Indexes for the directory in question:

<Directory /www/htdocs/images>
    Options +Indexes
</Directory>

Discussion

When a URL maps to a directory or folder in the filesystem, Apache will respond to the request in one of three ways:

  1. If mod_dir is part of the server configuration, and the mapped directory is within the scope of a DirectoryIndex directive, and the server can find one of the files identified in that directive, then the file will be used to generate the response.

  2. If mod_autoindex is part of the server configuration and the mapped directory is within the scope of an Options directive that has enabled the Indexes keyword, then the server will construct a directory listing at runtime and supply it as the response.

  3. The server will return a 404 (“Resource Not Found”) status.

Enabling directory listings

The real keys to enabling the server’s ability to automatically generate a listing of files in a directory are the inclusion of mod_autoindex in the configuration and the Indexes keyword to the Options directive. This can be done either as an absolute form, as in:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required