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
38 Comments so far


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…
I am using Indices on my “local” development work station and on my website. I have different issues with both; so there must be some apache conf issues. Fore example, I got my “local” working except the parent directory link does not show… my workstation shows the parent link but the css definitions don’t work. Both use the same setup!
Anyway, here are a few pointers…
1) Steve… you can control directories and files that apache displays with the following command,
IndexIgnore .htaccess readme.html dir.txt “!*”
The above line obviously does not include the three specific files given by name. The last definition “!*” will not display a file or directory that starts with an exclamation mark – which is how I had my private information.
2) If your .htaccess is setup in your doc root, *** remove the .htaccess in the “indices” folder *** or they will have conflicts.
As I wade through this experience and learn things, I will leave comments, and would appreciate if others would do the same :)
So simple & cool with your help, serious work, many thanks !
I am trying to use it on Ubuntu 10.04 LTS:
I can get something working (i.e. icons) but I need to AllowOverride All on the directory and I do not get the nice box, fonts and highlighting :(
any hint?
thanks for a great tool, got this working on a few places now
if a directory before had its own header.html file, how can we get it to include this info or overide the default indices info?
Hi,
first of all, great job!
I have some problems on my website, I follower instructions (extract zip file in root) but this is the result: http://summer.stidue.net
Why I have “php code” embedded in my HTML?
Thanks
In particular, seems that header..php and readme.php are found but are called like Static HTML files and not processed by php preprocessor….
Hi there! Does this work out of the box with Apache 2.2.x?
No idea, but it’s easy to try it and see. Probably.
any idea on how to get this to work on a mac with MAMP 2.0?
I moved indices to /extras and modified /extras/httpd-autoindex.conf and nothing happened.
Thoughts??
No ideas, sorry. (I don’t really “support” this — it’s pretty much up to folks to figure out how to make it work when it doesn’t.)
This is excellent! I couldn’t read the full file names or the directory names, but now everything is cleaned up. I’ve gotten the icons working, but for some reason, the header is not functioning. I used absolute URLs for the paths of all of the icons, and have tried relative AND absolute URLs for the header and footer files, but to no avail. Anyone have an idea of why that might not work? I know PHP is running on the server and all that …
Thanks in advance.
Hi Scott,
I had to change all PHP open short tags into header.php
from
<?=
to
<?php echo
since my installation does not support them.
Btw this is another reason I hate XML :)
Ref. http://php.net/manual/en/ini.core.php#ini.short-open-tag
+1 with Antonio
This rocks. I idly downloaded it, read and followed the README, hit a directory that gives a directory list, and wham! a neat listing in Arial. I dumped the .htaccess file in a virtual directory that does directory browsing and it even worked there. This is on a XP box running XAMPP, with scarcely any configuration post-install. Love it!
Vewy vewy pwitty!
I’m sure there’s a nice way from the htaccess directory to hide the /indices folder, no?
Not knowing the “right” way to do it, I renamed indices to .indices and changed all the paths in .htaccess accordingly.
Thanks for putting this out there. Turns a hackey file browser into something much more livable.
K
This is very cool. Just wondering if you have managed to get it to show a default favicon.ico , I have tried everything I can think of.
Any ideas
I did some major hackery of this, including translating the JS to jQuery (which is slightly more cross-browser) and I also migrated almost all the CSS to use CSS3 selectors instead of tacking a bunch of classes into the DOM tree. I also decided to move the JS and CSS into their own files so that browser caching can reduce the amount of bandwidth used to download them. I put my alterations up on Github: https://github.com/NSError/Apache-Indices
Tested in Safari 5, Opera, FF10, and IE9 and it seems to work OK.
Hopefully someone finds something there they like. (Otherwise, works for me so I’m happy).
Holy crap, that is great! I’ll update this page to point at yours when I have a chance.
Hi there.
Is there any way you could translate the whole htaccess into an instruction to use with nginx?
That would be great.
Thank you very much,
Bonsailinse
Great piece of code – thank you for sharing!
Great little piece of code. In order to get header.php to run on my hosting service’s server, I needed to use the following line as my AddHandler line:
AddHandler application/x-httpd-php5 .php
Just wanted to record that for posterity :) Thanks again.
Using Apache 2.2.x. I snagged NSerror’s version and changed the /indices/.htaccess to use:
Options -Indexes
SetHandler application/x-httpd-php
See:
http://www.php.net/manual/en/install.unix.apache2.php
Hello!Thank you for your effort!
Is there any way of traslating or changing the header row cells from the table? I mean the Name , Last Modified, Size. I want to show this 3 strings to another language.
Thank you