Odds & Ends
In addition to the directives we've already seen, there are some square pegs that don't fit into our round holes (and not surprisingly, they are all tools that are only marginally useful); let's take a quick look at them.
IndexOptions [FoldersFirst] [IgnoreCase] [ScanHTMLTitles]
The parameters shown above have the following effects:
FoldersFirst: if included, folders will always appear at the top of the list, and will then be sorted amongst themselves according to the relevant criteria.
IgnoreCase: if included, the lowercase and uppercase variants of a letter will be treated as equal when comparing names (ex: the documents "A.TXT" and "a.txt" will be placed in consecutive order)
ScanHTMLTitles: if specified, Apache will use the text between the
<title></title>tags in web pages (files ending with an extension of ".html" or ".htm") that don't have a description applied.
ScanHTMLTitles directive should be avoided for high-traffic sites, since every HTML file in the directory will be scanned to retrieve its title.
Apache 2's Additions
In addition to all of the configuration options that were introduced above, the 2.0.x branch of Apache also includes several auto-index directives that aren't available in the 1.3.x family. Most of these additions are small utilities that are to be tacked on to our ever-expanding utility belt, so let's take a quick peek at them:
IndexOptions [SuppressIcon] [SuppressRules] [VersionSort] [XHTML] [HTMLTable]
- The first two parameters,
SuppressRulesprevent the respective tags (
hr) from being included in the index.
VersionSortwill instruct Apache to sort files based on the file names and version numbers.
XHTMLwill instruct Apache to generate XHTML markup instead of HTML.
HTMLTablewill instruct Apache to create an HTML table (with
<td>tags) to align the columns in the index page instead of simple pre-formatted text.
Anyone familiar with web standards (or at least the HTML 4.1 DTD) will realize that Apache 1.3.x's pages don't validate for a couple of reasons:
- The pages use a fixed-width font (created through the use of the
<pre>tag to create an artificial table, and
- According to the specification, markup contained within a
<pre>tag can not contain the
<hr />elements (and by "cannot" we mean "shouldn't", since browsers have been designed to accept invalid markup).
Zeldman & Co. (myself included) will appreciate Apache 2 solely for the fact that its index pages are now able to validate; while this feature is relatively minor when compared to the other differences between 1.3.x and 2.0.x, it is one more step in the road to the Semantic Web. Making your pages validate can be accomplished in one of two ways:
- Include both the
SuppressRulesparameters to the
- Or alternatively, use the
HTMLTableparameter to direct Apache to create a proper HTML table to align the rows and columns of the directory listing.
The other advantage to using
HTMLTable is that it frees you to use a proportionally-spaced font (such as Arial, Verdana, Helvetica, or any other sans-serif font), instead of a fixed-width font such as Courier or Monaco). Which means that you're now able to use the same font face used throughout the rest of your site, making your index pages blend in that much more.
Apache's auto-indexes aren't the only option. It is a simple matter to create a server-side script with PHP (or Perl/CGI if you prefer the old school) to generate a custom index page with links to the directory's contents.
However, as with any solution there are pros and cons with this method; the main advantage being that you can customize the page in ways that aren't possible using Apache's configuration directives. While the main drawback is the increased load placed on your web server required to generate the page (due to the reduced performance of interpreted languages as compared to their pre-compiled cousins). But the choice is up to you.
We have just seen the entire menagerie of directives that alter Apache's auto- pages. Remember what Step 1 of this article was? It's time to go back and see what our original auto-page looked like. Now take a look at what this simple configuration file and CSS file produced:
Figure 10: The result of all our hard work. Contrast this image with Figure 1 to see how our auto-indexes have progressed.
The above page is a relatively simple example of what can be done using Apache's auto-index directives. If you've created a work of art using
mod_autoindex's directives, post a link in the Comments section and let's see what kind of gallery we can create. Happy indexing.
David Miller is combining his passions of photography and working on the web at iStockphoto; when not hacking away with a text editor and a few web browsers in hand, he can be seen huddled over his laptop tweaking levels and curves for his freelance photography. Keep track of David's latest projects over at his home on the web.
Return to MacDevCenter.com.
A set of icons
2005-09-04 21:34:55 ideopathic [View]
2004-10-16 12:04:45 ivetter [View]
2004-10-11 18:58:30 Chirael [View]
Page links broken?
2004-08-06 23:22:26 Lost_and_Found [View]
Page links broken?
2004-08-06 23:23:25 Lost_and_Found [View]
2004-08-04 14:13:39 nathanmcfarland [View]