Sep 30 2008

IndexStyleSheet for mod_autoindex

Let me preface this post by saying I only do this on my local Apache install, running on my local machine. I'm sure actual server admins would suggest an alternative way to handle such things on production servers. Consider this a quick and dirty mod that only caters to my your obsessive-compulsive disorder.

Nevertheless, as of Apache 2.2, which comes installed with Leopard, there's a new directive in mod_autoindex by the name of IndexStyleSheet.

According to the documentation:

The IndexStyleSheet directive sets the name of the file that will be used as the CSS for the index listing.

Basically, all you need to do is make sure the following autoindex Include is uncommented in Apache's conf. For Leopard, httpd.conf is located here:

/private/etc/apache2/httpd.conf

Right around Line 450 is the autoindex conf Include—make sure it's uncommented:

Include /private/etc/apache2/extra/httpd-autoindex.conf

Then, open up the autoindex conf in the editor of your choice:

/private/etc/apache2/extra/httpd-autoindex.conf

Near the bottom of the file, add the following line, as is suggested in the documentation (you can name the directory and CSS file anything you like):

IndexStyleSheet "/css/style.css" 

Finally, create said directory in your main DocumentRoot, create the aforementioned CSS file inside the folder and restart Apache.

It's up to you to style the directory index to your liking—look at the HTML source to get the structure. If you're feeling lazy, you can grab my CSS on Pastie. Note: after restarting Apache, changes to the CSS file will take effect with a simple refresh.

While not necessarily a helpful tip that will save you time and money, it will definitely spruce up those default Apache directory indexes. I develop locally, so I spend quite a bit of time looking at them.

5 comments

It's worth noting that the Directory directive for your DocumentRoot should include the Indexes option or Apache won't display directory indexes in the first place. If you're feeling lucky, mod_autoindex has plenty of other settings.

Robbie — Sep 30 2008

Very helpful.

Will — Oct 5 2008

Yes, you can customize output from the mod_autoindex. Apache's modules has many features and you can even produce XML from the directory list. If you are interested how, you can read on my post. Regards.

www.redips.net — Feb 22 2009

thanks thanks for that quickie, i hate the default fonts after installing WAMP

mark philippines — Aug 4 2009

Glad I could help, Mark. I hate the default layout, too.

Robbie — Aug 5 2009