This site is now 100% read-only, and retired.

Spicing up directory indexes with Apache

Posted by Steve on Tue 26 Jul 2005 at 13:51

There are times when you wish to just share a simple collection of files with Apache, so you place them into a directory and allow people to browse them. By default Apache's directory index isn't terribly pretty, here we'll show a couple of simple changes you which make these indexes nicer to use.

The most common problem with Apache's default directory index is that the column which show you the filenames aren't very wide.

Here is an example which highlights the problem:

Here you see can that there are two files with no obvious way to tell the two apart, short of "mousing over" their names and looking in the status bar.

There is a simple solution to this problem though, the directory indexing module mod_autoindex allows you to specify the width of this column, or instruct Apache to make the column as wide as it needs to be..

You can edit your Apache configuration file to include the following setting, this will cause the width of the filename column to expand sufficiently to include the full name:

IndexOptions NameWidth=*

The configuration file will be /etc/apache2/apache2.conf for Apache2, and /etc/apache/httpd.conf for Apache 1.x.

Instead of using the "*" character you can give a number, which will be used as the column width.

Once you have restarted the server visitors will now be given a much more readable index:

The other two changes you can make to your directory indexes to make them look prettier is to add a "header" and "footer" document.

The header will be displayed to clients who look at your directory index, above the list. The footer will, predictably, be placed beneath the index.

By default this support is already enabled. You simply need to create two files README.html which will be the directory footer and HEADER.html which will be the header.

If you don't have this support enabled it's simple to add the following to your Apache configuration file:

HeaderName HEADER.html
ReadmeName README.html

If you use Apache2 rather than Apache 1.x you gain access to several more directives which will allow you to spice up your indexes. These are described in the mod_autoindex documentation.

 

 


Re: Spicing up directory indexes with Apache
Posted by mority (213.144.xx.xx) on Tue 26 Jul 2005 at 14:59
Great! I always found it very annoying not being able to read the whole file name in the file index at a glance if it was a bit longer.

Thanks a lot for that clue :)

[ Parent ]

Re: Spicing up directory indexes with Apache
Posted by Anonymous (82.119.xx.xx) on Fri 29 Jul 2005 at 11:46
That NameWidth=* option works also with Apache 1.3.x.

[ Parent ]

Re: Spicing up directory indexes with Apache
Posted by Steve (82.41.xx.xx) on Fri 29 Jul 2005 at 13:08
[ View Weblogs ]

Thanks, you are correct.

I must have misread the Apache documentation and confused the setting with "DescriptionWidth" which is Apache 2.x only.

Steve
-- Steve.org.uk

[ Parent ]

Re: Spicing up directory indexes with Apache
Posted by ashayh (141.151.xx.xx) on Fri 29 Jul 2005 at 21:23
If you really want pretty Indexes, you might want to look at
http://autoindex.sourceforge.net/
Try the Demo.

[ Parent ]

Re: Spicing up directory indexes with Apache
Posted by sokam (202.154.xx.xx) on Thu 4 Aug 2005 at 14:56
IndexOptions FancyIndexing NameWidth=* FoldersFirst IgnoreCase
It makes my dirlist look better :)

[ Parent ]

Re: Spicing up directory indexes with Apache
Posted by Anonymous (124.170.xx.xx) on Thu 5 Jun 2008 at 05:59

For Apache 2.2.x, I typically use this:

Options +Indexes
IndexOptions +XHTML +IconsAreLinks +FoldersFirst +VersionSort +IgnoreCase +NameWidth=*
HeaderName HEADER.html
ReadmeName README.html

Very, very pretty. ;)

Cheers,
-Meitar Moscovitz
Personal: http://maymay.net/
Professional: http://MeitarMoscovitz.com/

[ Parent ]

Re: Spicing up directory indexes with Apache
Posted by eviltwin (217.154.xx.xx) on Tue 4 Oct 2005 at 16:53
If you want really fancy indexes you can stick my php fileNice app in the directory.

[ Parent ]

Re: Spicing up directory indexes with Apache
Posted by Anonymous (83.33.xx.xx) on Thu 26 Apr 2007 at 13:45
Genial!

thanks, i add it to my wiki

http://porcelinux.no-ip.info/mediawiki

[ Parent ]