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:
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.
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.
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:
Get Apache Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.