oreilly.comSafari Books Online.Conferences.


AddThis Social Bookmark Button

Mo' Betta Indexes
Pages: 1, 2, 3, 4, 5


Now that you've seen how to control how icons are embedded in the index, let's take a look at the ways to control how the metadata columns are displayed (or not). Again, it's time to break out the spork.

IndexOptions [NameWidth=n|*] [DescriptionWidth=n|*]
[SuppressColumnSorting] [SuppressLastModified]
[SuppressSize] [SuppressDescription] 

The first two parameters specify the width of the "Name" and "Description" columns in characters; n will make the column n characters wide, whereas * will make the column accommodate the longest filename. Each Suppress... parameter instructs Apache to not include the corresponding column in the auto-index page.

1.3.x 2.0.x

By including one (or more) of the suppression parameters, the corresponding column(s) won't be included in the index page. Specifying SuppressColumnSorting, however, will remove all of the links from the column headers to prevent visitors from sorting the file listing by anything other than the default value (which, not surprisingly, can also be changed).

By default, the order of the files in Apache's index pages can be sorted by any of the four columns in ascending or descending order. Figure 9 is a screenshot of an index page with column sorting and the "Description" and "Last Modified" columns suppressed and the "Name" column decreased in size:

An example of altering the displayed columns
Figure 9: An example of altering the index columns through the parameters of the IndexOptions command.

At this point, no files in our index have a description attached to them, so sorting the index by description in ascending or descending order has no effect. The AddDescription directive, not surprisingly enough, allows us to add descriptions to files.

AddDescription string pattern [pattern] ... 

AddDescription operates in virtually the same fashion as the AddIcon and AddAlt directives.

1.3.x 2.0.x

The description for a file can be virtually any markup that you can dream of ( including HTML tags). For example, the directive

AddDescription "<a href=\"\"
title=\"QuickTime Movie\">QuickTime movie</a>" *.mov 

will include a link to QuickTime's web site so that visitors can download the plugin.

As you can see from the above image, the files are sorted in ascending alphabetical order by default, meaning that A.txt comes before Z.txt, which in turn comes before a.txt. Should you need to alter this (if you wish to sort by size or by descending order, for example), then the IndexOrderDefault directive is what you need.

IndexOrderDefault Ascending|Descending 

The parameters to the command govern how the files will be sorted in auto-index pages by default; the first indicates which direction the values are sorted in, and the second indicates which column contains the keys to sort by.

1.3.x 2.0.x

It is also possible to pass a parameter to the generated page to sort the columns based on the user's preference. The parameter is passed as a key=value pair, and the key can be one of:

  • N for "Name",
  • S for "Size",
  • D for "Description", or
  • M for "Date Modified"

And the value can be one of:

  • A for ascending
  • D for descending

For example, let's inspect the following example URLs:

In the event that an invalid parameter is passed (such as in the URL http://localhost/?Y=Z), then Apache will ignore the parameter and generate the file listing according to the directives included in its configuration file.

Headers & Footers

We now know how to control the portion of the page that lists the directory's contents. The next step is to control the content that appears before and after the listing.

HeaderName filename

If a file with the given filename is present in the requested directory, the contents of it will be inserted into the index page before the file listing, but after the HTML preamble. If the given file does not exist, then the top of the document will appear the same as if the directive wasn't included in the configuration file.

1.3.x 2.0.x

This allows you to include special instructions in the index page that visitors may need to read before downloading the directory's contents.

IndexOptions SuppressHTMLPreamble 

One more step that can be made with respect to the header of the document is to insert our own fragment as the header of the page, which allows us to control everything that comes before the file listing.

1.3.x 2.0.x

By suppressing the HTML preamble, it is possible to incorporate your own site's templates into your index pages. And it is now possible to use your site's CSS stylesheets to tweak the page's appearance and JavaScript library to govern its behavior. The following snippet is just one example of what can be inserted into a header file:

    <title>Widget 3001 Downloads</title>
  <link rel="stylesheet" type="text/css" href="/c/lib.css"/> 
    <link rel="icon" type="image/png" href="/icon.png"/>
    <script type="text/javascript" src="/j/lib.js"></script>
    <h1>Download Widget 3001!</h1>
    <p>Get the latest releases here: </p>
     <!-- file list will be appended here --> 

By default, Apache will include a signature on its index pages, which looks something like Apache/1.3.29 Server at localhost Port 80 (the details of which will vary according to your site's configuration, of course). It is possible to remove this signature and use your own markup in its place.

ReadmeName filename 

The readme file behaves similar to the header file, except that it is appended to the page after the file listing has been included, rather than before.

1.3.x 2.0.x

If the ReadmeName file is found, then it is placed below the file listing in our auto-index page instead of the server's signature, which typically looks something like (the values displayed will vary based on your version and host, of course) "Apache/1.3.29 Server at localhost Port 80."

Pages: 1, 2, 3, 4, 5

Next Pagearrow