?

Log in

No account? Create an account

Apache pitfalls

« previous entry | next entry »
Feb. 3rd, 2013 | 11:58 pm

This post is for for anyone who's wrestling with the HeaderName and ReadmeName directives of Apache's mod_autoindex module.

I had some issues with these earlier: they were mysteriously not working under certain circumstances. The specified files wouldn't show up in some directories but in others; permission problems, different .htaccess settings etc. were all ruled out. The same files consistently worked/didn't work across directories, which suggested it was a file content issue.

Different encodings, line end conversion issues, presence of weird characters (BOM etc.) were ruled out. All files were plain text, so it couldn't have been HTML issues. Browser issues were ruled out: sniffing the network traffic unambiguously proved that Apache wasn't including the files' content in some cases. I eventually whittled it down to a file that worked, and ceased working when I removed one character. Slightly different files of the same or greater length did not work, ruling out file size as a factor.

Long story short, the answer was eventually found in an old mailing list post from 2000. Looking back at the Apache documentation, I can see it says this:

Filename must resolve to a document with a major content type of text/* (e.g., text/html, text/plain, etc.)

The files in question did not have a file extension, so based on my experiences and on the above paragraph, I'd wager a guess that Apache's peeking at the file to determine if it's indeed a text file (in the above sense) and, for very short files, wrongly concluding that it's not.

The fix, thus, is to add a section to a relevant .htaccess file or your Apache configuration, as suggested in the mailing list post linked above:

<Files ~ "(README|HEADER)$">
ForceType text/plain
</Files>

As before, though, I really wish there'd have been SOME sort of indication of why this isn't working, though, perhaps a log entry or so telling you that the file in question was determined to not be a text file.

Link | Leave a comment | Share

Comments {0}