Apache 2 File Sorting by Extension
Saturday, 30. June 2007, 22:45:04
It can be configured to sort files by extension (not directly though).
The trick is simple - sort files by description by default, with alphabetic descriptions added for file types. So *.exe-files with an "Executable file" description would always be sorted before *.zip-files with a "Zip archive" description.
For the server configuration file (usually httpd.conf):
LoadModule autoindex_module modules/mod_autoindex.so - this ensures the Autoindex (directory reader/indexer) module loads, it is required by the Fancy Indexing.
Include conf/extra/httpd-autoindex.conf - this is the included configuration file itself.
In httpd-autoindex.conf:
IndexOptions FancyIndexing HTMLTable VersionSort DescriptionWidth=* FoldersFirst IgnoreCase NameWidth=*
IndexOrderDefault Ascending Description
The IndexOptions directive takes:
FancyIndexing - ensures directory sorting is enabled and can be toggled by the sorting type column headers;
HTMLTable - creates a simple single table for the file list. It can cause strange behaviour in really old browsers, but it is necessary for proper UTF-8 read formatting (which can alternate between left-right and right-left);
VersionSort - enables version sorting (where 1.11 will be displayed after 1.8.1);
DescriptionWidth=* and NameWidth=* - the asterisk removes any width limitations - the column will be as wide as the widest name or description;
FoldersFirst - display directories first, not mixed alphabetically with files;
IgnoreCase - ignore case (default behaviour is to sort all capital-letter names first);
The IndexOrderDefault directive is set-up to sort directories by description in ascending order.
The AddIcon directive adds an icon for a new file type.
The AddDescription directive provides a description for a file type:
AddDescription "Zip archive" .zip
With appropriately-described extensions, the file list should be sorted by extension:
Some notes: Apache 2 prioritised directives according to the order they were read in. httpd.conf had icons and descriptions for generic filetypes loaded first:
AddIcon /icons/binary.gif .bin .exe .lib .stub
AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv
AddIconByType (TXT,/icons/textdoc.png) text/*
AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip .rar
Those should be moved to a position after the newly added icon/descriptions.
Some little quirks in the way Apache 2 treated extensions: if a description for *.xml came after a description for *.xm, all *.xml would be treated as *.xm . Apache 2 also read only the first extension for sorting, not the last (so .avi.torrent would be sorted with *.avi, not *.torrent), but it generated descriptions correctly, by the last extension.
HeaderName /Fileindex.html
ReadmeName /Filefooter.shtml
Those directives specify the header and the footer for file indexes. The header can provide the background and body setup (fonts, colours, images, etc.). If server-side includes (SSI) are on, files marked as SSI-capable (*.shtml, etc.) will be parsed for includes, so common environment strings like server signature, local time/date, etc. can be inserted into the header or footer.

How to use Quote function: