Apache - Modifying directory listings
Modify Apache's directory view (FreeBSD 6.2)
Posted 23.05.2009 | Updated 23.05.2009 | Contributed by Andy Mallett


The directory listing view in Apache is what you see if there is no index.* file in the directory which is being viewed.

In the absence of an index.htm (or index.html, index.php, etc.) Apache may reveal a listing of all files and directories in the directory being viewed.

The may refers to the possibility that this feature might be turned off as some consider it a security risk.

All web directories generally contain an index file and its presence prevents the ability to view a directory listing - the viewer is simply shown the index file itself, which links to other files in the usual way.
However if directory listing view is enabled in the Apache server's configuration and there is no index file, then the reader is presented with a view similar to this:

Apache directory listing

This view can be useful if you use the directory as a repository for files and can't be bothered to create an index file, which hyperlinks to each file listed. An alternative is to leave out the index file and enable directory view in httpd.conf. Under these circumstances Apache makes the list for you and users can download the files by clicking on the list. Nice.

One limitation is that longer file names get truncated in the default directory list view. Hard to read. To widen the view, edit httpd.conf..

Modifying httpd.conf

This file is the main configuration file for Apache and it is wise to make a backup before modifying it, just in case..

cp  /usr/local/apache/conf/httpd.conf   /usr/local/apache/conf/httpd.conf.bak

Note that the location of httpd.conf can vary depending on the system and version being used. Edit the file and add the lines in the box below. You can enter the lines near other directory config entries which start with the <Directory> tag..

vi  /usr/local/apache/conf/httpd.conf

 <Directory /usr/local/apache/htdocs/fpriv>
 IndexOptions NameWidth=*
 </Directory>


Note that the example targets the directory /usr/local/apache/htdocs/fpriv. Modify the line to suit the path to the directory you wish to view in wider mode. Save the changes and exit from the editor.

To make the changes happen, restart the Apache Service. Again the method may vary..

/usr/local/apache/bin/apachectl   restart

The new directory listing view should widen to accomodate the longest file name..

Apache directory listing