oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Mo' Betta Indexes

by David Miller

While web sites often incorporate a standard look and feel across all of their pages, any generated index pages included in the site typically stick out like a sore thumb. So let's see if we can't incorporate the look and feel of a sample site (barren though it may be) into a page that Apache will automatically generate.

Note: The term "Apache" typically refers to both the Apache Software Foundation and the Apache httpd (web server) project. To avoid any confusion, I will refer to the Apache Software Foundation simply as the ASF, and to the ASF's httpd project as Apache.

What Isn't Covered

This article will not go into detail regarding the structure of Apache's configuration file; both the project's online manual and O'Reilly's Apache: The Definitive Guide, 3rd Edition (Ben Laurie, Peter Laurie) provide a comprehensive reference. In addition, the inline documentation included in the default configuration file provides an excellent starting point.

Instead, I'll focus specifically on the directives that we'll be using to accomplish our task: to incorporate Apache's auto-index pages into an existing web site's look and feel. If the term "directive" is foreign to you, then you may want to peruse these documents before continuing, since a detailed tutorial on how to get Apache up and running is beyond the scope of this article. However, links will be provided to the related section of Apache's online manual (for both versions 1.3.x and 2.0.x) when appropriate.

What Is Covered

Because of the complexity of running a web server that can host hundreds of domains and the httpd daemon itself, most of Apache's configuration directives relate to technical aspects. Aspects such as security and authentication, hosting, administration, module management, and other aspects that aren't readily apparent to a site's visitors. However, there are some simple directives that are accessible to anyone familiar with Apache that can make a dramatic difference in the appearance of your site's auto-indexes.

Most commercial web sites and desktop applications have thousands upon thousands of dollars poured into their design and interface. While Apache's client-side and open-source cousin Firefox has recently undergone a facelift, Apache has had the same skin since around 1995 when it was still under the wing of its founder, the National Centre for Supercomputing Applications (NCSA). And while it's true that visitors interact with their web browser and the pages of your site much more than the HTTP daemon that's pulling the strings on your web server, the only real snapshot they'll receive is through your site's auto-indexes (unless an error page rears its ugly head). So why not take some time to put some spit and polish into them?

Split Personality

Apache has been the Net's most popular web server since early 1996, and has been available in two versions (1.3.x and 2.0.x) since 2001. As has been previously documented, migrating from the previous version to the latest isn't quite as simple as stopping the old daemon and starting up the new.

Some of the changes are esoteric, but most are due to changes in the architecture between versions; modules had to be rewritten, configuration files have to be modified, and settings must be tweaked.

Luckily, most of these changes do not apply to the work we'll be doing today. In this article, we'll make use of two modules: mod_autoindex and mod_dir (and a smidgen of mod_alias). The differences between these modules across Apache's two versions are mostly limited to new features that have been added in the latest releases, and those features will be marked as such.

Precautionary Steps

So we're almost ready to go. But before we get started, there are two very important steps we must take:

  1. The single most important thing to do is to create a backup copy of the configuration file in case we mangle it beyond repair and can't get the daemon to start up again. To do so, type the following into your Terminal window: sudo cp /private/etc/httpd/httpd.conf /private/etc/httpd/httpd.conf.noindex (The command line is wrapped due to space constraints; be sure to hit Return only after entering/copying it in its entirety).

  2. The second most important step (which is relatively minor compared to #1) is to take a snapshot of Apache's default index page to serve as the reference point in our "before" and "after" comparison. The page on your server may appear a little different from the following, but it should be pretty much identical to the Figure #1.

An example of Apache's default auto-index page
Figure 1: A typical index page, as created by Apache's default configuration file on OS X.

Now let's turn that eyesore into something a little more pleasing.

Pages: 1, 2, 3, 4, 5

Next Pagearrow