Desktop and Server Virtualisation Specialist 

Twitter LinkedIn E-mail
Precedence Technologies Ltd
Technology House, 36a Union Lane
Cambridge, CB4 1QB, United Kingdom
T: +44 (0)8456 446 800 / +44 (0)1223 359900
E: enquiries@precedence.co.uk
Home right arrow Support right arrow Internet Services right arrow Directorylisting

Using .htaccess files to control directory listings

At Precedence Internet, we use a webserver called Apache. This is most widely used webserver in the world. Apache is highly configurable and it is possible for some options to be set by the end user. This is performed by creating text file called .htaccess in your directories.

A brief guide is given below, but this is no substitute for having read the Apache documentation.

Configuring directory listings

If you create a directory without a suitable home page in it (index.html, index.htm, index.php, index.php3, index.txt), then an access denied message (headed with Forbidden) will be displayed in the browser. This is to stop you accidentally making internal or private files available. If you want to display a directory listing, this can be enabled. It is often useful to define descriptions and headers/footers for such listings. For example, look at this page. Boring, isn't it? Now look at this page.

The second example is a copy of the first, but it has had a header and a footer added. Also, each item has been given a short description and one item has been hidden.

To do this, firstly create your header and/or footer files as plain text files. In this example, they are called header.txt and footer.txt. Use the following lines in your .htaccess file:

CommandDescription
Options +IndexesEnable directory listing
HeaderName <filename>Use <filename> as a header
ReadMeName <filename>Use <filename> as a footer
IndexIgnore <filename>Ignore <filename> when listing the directory
AddDescription "description" <filename>Use description as a description for <filename>
For example, the .htaccess in the second example was:
Options +Indexes
HeaderName header.txt
ReadMeName footer.txt
IndexIgnore header.txt
IndexIgnore footer.txt
IndexIgnore old-stale-fish
AddDescription "Nice in batter" cod
AddDescription "Sweeter than cod" haddock
AddDescription "Sort of flat" plaice
© Copyright Precedence Technologies 1999-2024
Time elapsed:0.020