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.
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:
Figure 9: An example of altering the index columns through the parameters of the
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
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=\"http://www.apple.com/quicktime/\" 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 Name|Date|Size|Description
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.
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:
Dfor "Description", or
Mfor "Date Modified"
value can be one of:
For example, let's inspect the following example URLs:
- http://localhost/?N=A - sorts by name in alphabetical order (this is equivalent to passing no parameters when the
DefaultSortOrderhasn't been altered)
- http://localhost/?S=D - sorts by size in descending order
- http://localhost/?D=D - sorts the contents by description in reverse-alphabetical order
- http://localhost/?M=A - sorts the contents by modification date in ascending order (oldest files first)
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.
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.
This allows you to include special instructions in the index page that visitors may need to read before downloading the directory's contents.
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.
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.
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.
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."