9.5. Modifying an Auto-Indexed File List to Match Your Site's Design

Problem

You want to automate the creation of a menu page for a directory of files and make it look like any other page on your site.

Solution

Use the IndexOptions, HeaderName, ReadmeName, and IndexIgnore directives in an .htaccess file to instruct Apache's automatic index generation on how to customize the file list. The code below converts the file list on the left side of Figure 9-5 into the page shown on the right side of Figure 9-5:

	Options Indexes
	 IndexOptions FancyIndexing SuppressDescription SuppressHTMLPreamble
	 HeaderName header.html
	 ReadmeName footer.html
	 IndexIgnore header.html footer.html .htaccess

Discussion

If the mod_autoindex module is enabled on your web server, Apache can generate an automatic list of files when a directory on your web server does not contain a default HTML page (typically named index.html).

If you have the ability to open and modify your Apache configuration file, check to make sure the following two lines are not commented out. The two lines you're looking for should be near the top of the file:

	LoadModule autoindex_module

and:

	AddModule mod_autoindex.c
A few Apache commands make an auto-generated file list (left) more presentable

Figure 9-5. A few Apache commands make an auto-generated file list (left) more presentable

Tip

The location of Apache's configuration file—httpd.conf—is set at installation. The default location is /etc/httpd/conf/httpd.conf. A commented, ...

Get Web Site Cookbook 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.