GuidesApache Guide: Generating Fancy Directory Listings with mod_autoindex Page 2

Apache Guide: Generating Fancy Directory Listings with mod_autoindex Page 2

ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.


The IndexOptions directive provides a list of options to set
various features of the index listing. These options don’t
warrant their own directive, and so are lumped together here.

The syntax of the IndexOptions directive is:

     IndexOptions +option1 -option2 ...

Options marked with + will be included in the set of options, and
those marked with – will be ommitted. Note that if you forget the
+ or – in that list, the last item on the list is all that you
get. That is,

     IndexOptions SuppressDescription ScanHTMLTitles

is exactly the same directive as

     IndexOptions ScanHTMLTitles

And, furthermore, it overrides all previous IndexOptions directives
that are already active. Don’t forget the + and –!

I’m not going to go over all of the available options – see the
docs – but here are a few that I like.

List Folders First

Those of you that are used to a graphical representation of your
directories — something like the Windows file explorer, for example —
are used to seeing the directories at the top of the listing,
and the files below that. The default Apache view is to have the
directories listed in the same alphabetic ordering as the files.

To override this behavior, use the FoldersFirst option:

     IndexOptions +FancyIndexing +FoldersFirst

Note that the FancyIndexing option is necessary for several of the
options to work, including this one.

Descriptions from HTML

Using the ScanHTMLTitles option, you can get a
description of each HTML file in a listing by looking in the

tag of each file. If you have written good HTML, this<br /> will give a very good idea of what each file is, before the user downloads.<br /> Note that in order to do this, Apache will need to open each file and<br /> parse it looking for a title tag. This can take a long time, and<br /> use up a lot of system resources.</p> <h2><a name="describe%20your%20files" id="describe your files">Describe your Files</a></h2> <p> An exceptionally useful feature of <code>mod_autoindex</code> is the ability<br /> to provide descriptions for your files, and have these descriptions<br /> appear in the directory listing. This is accomplished with the<br /> <code>AddDescription</code> directive. As with several of these directive,<br /> you can specify exact file names, or you can give wild-cards to<br /> indicate a group of files.</p> <pre> AddDescription "My dog" /images/fido.jpg AddDescription "PNG images" *.png</pre> <p> If you are in the habit of using really long file descriptions,<br /> or if you are using the <code>ScanHTMLTitles</code> option above, you<br /> might find that the space allocated to you for displaying a<br /> description is insufficient. You can correct oft this with the<br /> <code>DescriptionWidth</code> option. This is an option for the<br /> <code>IndexOptions</code> directive. You can specify a particular<br /> width, or you can specify ''*'', indicating that the field should<br /> be wide enough to accomodate the largest description you<br /> have.</p> <pre> IndexOptions +DescriptionWidth=42</pre> </p> <h2><a name="readme%20files" id="readme files">Readme Files</a></h2> <p> OK, one more. It may be desirable to display some informative<br /> text at the top of a directory list. This may be information about<br /> the files in the directory, or it might be administrative information<br /> about the server. Or whatever. The <code>HeaderName</code> and <code>ReadmeName</code><br /> directives allow you to indicate a file that will be put<br /> at the top or bottom (respectively) of the directory listing.<br /> The argument for this directive is a filename stub. That means<br /> that if you have:</p> <p>

Get the Free Newsletter!

Subscribe to Daily Tech Insider for top news, trends & analysis

Latest Posts

Related Stories