Don’t call me DOM

3 September 2004

Making Apache automatic indexes valid

Filed under:

Apache, as probably most Web servers, have this feature where it will show an HTML formatted list of the files and directories under a given directory if no so called “index” files was provided, through its autoindex module; while it can prove handy, especially when used with the HeaderName and ReadmeName directives, it has a major drawback: its output is not HTML valid!

Even though the code sets a proper doctype, it uses the <img> tag inside a <pre> elements, which is not allowed in HTML 3.2 (nor in the following versions):

<!--=================== Preformatted Text =================================-->

<!-- excludes images and changes in font size -->

<!ENTITY % pre.exclusion "IMG|BIG|SMALL|SUB|SUP|FONT">

<!ELEMENT PRE - - (%text)* -(%pre.exclusion)>

(see some background discussion on why this is so)

That means that when we use this feature on the W3C Apache servers, we produce invalid HTML pages! Of course, it happens regularly that we get invalid content on our site (errare humanum est), we usually make a good job of fixing it, thanks to the LogValidator ; but the case of Apache indexes is more tricky, since the content is not really produced by us.

Still, perseverare diabolicum, and I finally decided to take the time to produce a patch changing 13 lines of code in mod_autoindex.c, replacing the <pre> container by a proper <table>; it could do more, use better semantics, use XHTML instead of HTML 3.2, have a referenced style sheet, a proper encoding, etc., but at least it works as a first step.

It should apply on Apache 1.3.31, and probably other versions too.

I haven’t submitted it to Apache yet; I’m not sure if it would be accepted since it was done on the 1.3 branch, and it is not mission-critical; but I’ll look into doing it if the problem still exists in Apache 2.

Comments are closed.

Picture of Dominique Hazael-MassieuxDominique Hazaël-Massieux ( is part of the World Wide Web Consortium (W3C) Staff; his interests cover a number of Web technologies, as well as the usage of open source software in a distributed work environment.