Hosting Fanatic

Go Daddy $1.99 Domains 468x60
Adam Sullivan - Friday 13th of June 2008 03:35:36 AM

Customizing Apache Directory Indexes

What Indexes Are We Talking About?

Apache directory index? Huh? Maybe I should explain what I'm talking about here. Have you ever gone to a url only to find a list of files and directories in the folder you are accessing? When you click on a file many times you will browse to another page or be given the chance to save the file to your hard drive.

These are the indexes I'm talking about. Many times webhosts have their servers set up to display these indexes when someone goes to a folder on a website that doesn't have a default page(index.html or default.html, etc). Many times this isn't needed and may be harmful as someone could view files in a folder that you don't want people to know exist. An example might be a PHP based site with an includes folder. The files in the includes folder aren't meant to be viewed and messed around with seperately but only used by other files to dynamically generate web pages.

This is why many people simply turn indexes off. There are a few different ways to do this that depend on what type of hosting you have and how your server is configured by my personal favorite is to add the line Options -indexes to the .htaccess file in your web directory. Instead of generating indexes when someone accesses a folder without a default file the visitor will see an access denied error page.

There are situations, however, where the indexes can be quite handy. I will use the .htaccess file to manage the index options in this tutorial and I will assume that indexes are turned off. The examples I use will be situations where we turn indexes on for one directory and all of its sub directories. That being said lets turn the indexes on and do some customization!

This article is a work in progress. Please check back.

Blink   Del.icio.us   Digg   Furl   Google   Simpy   Spurl   Y! MyWeb