SCOTT EVANS Mostly about pointing microphones at loud things.

Indices

Before and after screens. Click for a big version.

Before and after screens. Click for a big version.

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.

View a demo index here.

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

Download (v1.1, sept 1 2009)
15 comments

15 Comments so far

  1. Adrian January 12th, 2010 2:58 pm

    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.

  2. Steve January 18th, 2010 10:25 am

    Is there anyway to specify folders or files to omit from the directory listing?

  3. gse January 18th, 2010 11:06 pm

    @Steve – That kind of thing should be done with Apache configuration; Indices’ purpose is to style Apache’s output.

  4. Steve January 25th, 2010 9:39 pm

    @gse – Thanks. I should have searched Google first. IndexIgnore is what I needed.

  5. Paul D February 14th, 2010 1:58 pm

    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

  6. bharris February 19th, 2010 8:50 am

    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.

  7. deadelvis February 22nd, 2010 2:25 am

    Too bad “.. parent directory” link and/or arrow does not show! :(

    Couldn’t figure out how to fix it either.

  8. deadelvis February 22nd, 2010 2:34 am

    Nevermind… figured it out. It’s just hidden in the CSS. Bad call if you ask me.

    Thx for the nice work with this!

  9. adlwtn March 12th, 2010 10:47 am

    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.

  10. gse March 22nd, 2010 7:49 pm

    @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.

  11. Imran-UK April 22nd, 2010 3:20 am

    @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.

  12. Matthew June 28th, 2010 11:00 am

    Wanted to thank you. I’ve been using this for some time now and it really pretties up the mess.

  13. tom June 30th, 2010 12:21 am

    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?

  14. Cristian Granados July 2nd, 2010 9:31 am

    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!

  15. Jordan July 25th, 2010 7:32 pm

    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…

Leave a reply