Spicing up directory indexes with Apache
Posted by Steve on Tue 26 Jul 2005 at 13:51
There are times when you wish to just share a simple collection of files with Apache, so you place them into a directory and allow people to browse them. By default Apache's directory index isn't terribly pretty, here we'll show a couple of simple changes you which make these indexes nicer to use.
The most common problem with Apache's default directory index is that the column which show you the filenames aren't very wide.
Here is an example which highlights the problem:
Here you see can that there are two files with no obvious way to tell the two apart, short of "mousing over" their names and looking in the status bar.
There is a simple solution to this problem though, the directory indexing module mod_autoindex allows you to specify the width of this column, or instruct Apache to make the column as wide as it needs to be..
You can edit your Apache configuration file to include the following setting, this will cause the width of the filename column to expand sufficiently to include the full name:
The configuration file will be /etc/apache2/apache2.conf for Apache2, and /etc/apache/httpd.conf for Apache 1.x.
Instead of using the "*" character you can give a number, which will be used as the column width.
Once you have restarted the server visitors will now be given a much more readable index:
The other two changes you can make to your directory indexes to make them look prettier is to add a "header" and "footer" document.
The header will be displayed to clients who look at your directory index, above the list. The footer will, predictably, be placed beneath the index.
By default this support is already enabled. You simply need to create two files README.html which will be the directory footer and HEADER.html which will be the header.
If you don't have this support enabled it's simple to add the following to your Apache configuration file:
HeaderName HEADER.html ReadmeName README.html
If you use Apache2 rather than Apache 1.x you gain access to several more directives which will allow you to spice up your indexes. These are described in the mod_autoindex documentation.