Apache directory indexes

Sometimes you just want to publish a directory on the file system the easy way, which is why the mod_autoindex module for Apache exists.

The simplest way to have Apache list a directory is to add the “Indexes” parameter to the Options directive inside the directory definition where listing is desired. Like this:

  Options FollowSymLinks Indexes MultiViews

Red Hat Enterprise and Fedora Linux come with a supplemental conf file that enables some (but nowhere near all) autoindex features (found at /etc/httpd/conf.d/autoindex.conf). Another way of controlling autoindex is to set various features up in an .htaccess file in the target directory.

The default Red Hat config turns on FancyIndexing, which out of the box chops off the ends of long file names and inserts a continuation (“..>”). I find this extremely annoying, and unhelpful, when trying to navigate listings. To fix it all I had to do was add the “NamedWidth=*” parameter to the IndexOptions line in autoindex.conf, thus:

IndexOptions FancyIndexing HTMLTable VersionSort NameWidth=*

If you’re like me and link to quite a few directory listings, you might want to set a “global” header for all those pages. Doing that requires a couple of adjustments to autoindex.conf, as well as creating a header and footer file. In the following example the directories I’m publishing are /data/install, symlinked to /var/www/html/install and /data/media, symlinked to /var/www/html/media. My primary stylesheet is the same main.css that features in my using a movie as a web page background.

Edit autoindex.conf to change the text alongside ReadmeName and HeaderName, thus:

ReadmeName /include/FOOTER.html
HeaderName /include/HEADER.html

Now create those files under /var/www/html/include (or wherever your DocumentRoot points to).


<!DOCTYPE html>
<title>Casa Lembo</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel=stylesheet href="/css/main.css">
<h2>Casa Lembo</h2>
    <a href="https://onemoretech.wordpress.com">Onemoretech </a>&bull;
    <a href="http://www.bbc.com/news">Global News </a>&bull;
    <a href="http://tycho.usno.navy.mil/simpletime.html">Current Time </a></br>
    <a href="/media/podcasts/podcasts.html">Media Streams </a>&bull;
    <a href="/install/">Software Library </a>&bull;
    <a href="/media/">Shared Media </a>&bull;

And FOOTER.html:


Then restart Apache to make these changes effective. Test by going to one of the published directories and checking to see if the header displays.

This entry was posted in Development, System Administration on by .

About phil

My name is Phil Lembo. In my day job I’m an enterprise IT architect for a leading distribution and services company. The rest of my time I try to maintain a semi-normal family life in the suburbs of Raleigh, NC. E-mail me at philipATlembobrothersDOTcom. The opinions expressed here are entirely my own and not those of my employers, past, present or future (except where I quote others, who will need to accept responsibility for their own rants).