Indices
Download (v1.1, sept 1 2009)
Apache’s default directory index pages are ugly. Indices is a set of hacks that makes them pretty, and more usable.
What it does
- Simple, clean design
- Easily customizable logo and link at the top
- Optional readme.html file inserted before file list
- Long filenames are visible
- Directory names in bold; trailing slashes stripped from directory names
- Nice file icons
- Output is XHTML 1.0 Strict, styled with CSS
- Should be easy to modify for your own needs
How it works
Unlike other PHP-based solutions, Indices is based on Apache’s built-in directory mechanism, so it’s pretty easy to seamlessly integrate it into your entire website.
Indices uses a few helpful Apache mod_autoindex directives, coupled with a bit of CSS and (optional) Javascript hackery. The README talks about installation and how everything works.
If you’re curious about the plumbing, read this blog post.
Requirements
I developed Indices for my web server, which runs Apache 2.0.x and PHP 5.1.x. It’ll probably require some tweaking to get it working with earlier versions of either.
If you’re running Apache 1, you’ll be able to use some of this code for inspiration, but you’ll need to do a lot more hackery.
Download
15 Comments so far
Leave a reply

I love this as it’s very easy to use and is non-intrusive. Nicely done.
Just a point about the README – it may be useful to add that if you are installing this to a directory that is not under the htdocs path using the Directory directive, you need to include the line:
AllowOverride Indexes Options
Thanks for sharing your excellent solution.
Is there anyway to specify folders or files to omit from the directory listing?
@Steve – That kind of thing should be done with Apache configuration; Indices’ purpose is to style Apache’s output.
@gse – Thanks. I should have searched Google first. IndexIgnore is what I needed.
I had to include ‘FileInfo’ to my AllowOverride directive to supress the ‘AddType not allowed here” error. So my line would look like:
AllowOverride Indexes Options FileInfo
For some reason on my CentOS 5.4 system I had to turn on short_open_tag for indices to operate properly. I ended up just adding:
php_flag short_open_tag on
…to the start of the .htaccess file.
Thanks for your effort in a great bit of code.
Too bad “.. parent directory” link and/or arrow does not show! :(
Couldn’t figure out how to fix it either.
Nevermind… figured it out. It’s just hidden in the CSS. Bad call if you ask me.
Thx for the nice work with this!
I did everything as the instructions say… yet it doesn’t seem to do anything. I added the indices directory to my website’s root directory, and renamed main-htaccess to .htaccess (i had nothing in my .htaccess previously so it shouldn’t cause an issue).
Do I need to modify my httpd.conf file? Because that’s empty for me.
Sorry, I’m newish to the whole apache2 thing.
@adlwtn – Hard to say what’s going on. Be sure you have htaccess files enabled in your Apache config? Maybe ask a friend who’s an Apache expert to help you out. Sorry but I don’t have much time to support Indices.
@adlwtn
The zip contains a subdir called indices, make sure that and not the indices-1.1 is in your docroot.
The .htaccess file should be copied to the directory you’re planning to pretty index.
Odd that you’re main Apache config is blank. Double-check this. Normally /etc/apache2/apache2.conf on modern Linux-systems. The other possibility is that the main config file, or vhost file/config, has “AllowOveride None” somewhere as this would preclude the use of .htaccess files.
Generally I think it is better to use the main config file rather than .htaccess unless there is a good reason not to.
@gse – thanks very much for writing this. I sent an email just now with some feedback.
Wanted to thank you. I’ve been using this for some time now and it really pretties up the mess.
Hi,
Thanks for sharing this wonderful code!
I’ve added the code as described.
# In order for the PHP file to execute in a header, need to have a major type of text
AddType text/html .php
AddHandler application/x-httpd-php .php
Options -Indexes
Everything is working except, there’s always one folder missing. It’s always the first folder on top. When I sort folders by name it’s just the opposite. The first folder is visible and the last folder is hidden. Is there anything I can do?
Thanks, it works wonderful!
To make a parent directory link just add:
<a href="../">Parent Directory</a>
in the header.php file, in to the body section. You can custumize the aparence with css
Grettings
Pura Vida Costa Rica!
Tom: Your problem might be that the css specifies that the first row of the table shouldn’t be shown. I ripped out the static CSS because I was having problems with php, and i noticed the same thing. I imagine the php file itself is supposed to determine when it’s in the root of the domain (therefore there’s no parent directory link) and not include that CSS, but it’s probably broken for you.
Hmm, then again, that might not be it since if you reverse sort it does the opposite behavior? Not sure, but maybe it will help…