Skip navigation.

Apache 2 File Sorting by Extension

,

Apache 2 has a "Fancy Indexing" option for file lists.

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.

Quake II BugsCowon T2

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies

December 2009
S M T W T F S
November 2009January 2010
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31