Using .htaccess files to control directory listingsAt 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 listingsIf 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:
|Options +Indexes||Enable 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>|
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