Creating dynamic index.html

I know that if I go to a directory that does not have an index.html
file, the index will automatically generate a listing of the files in
that directory that is up-to-date with the most recent changes.

However, some software I am using to create photo albums points to
index.html in the parent directory as a home page. Some albums contain
hundreds of files pointing to this non existent file. In order not to
get a file not found message I need to create an index.html file in that
directory but I want that index to actually reflect any changes to the directory. In effect, I want index.html to display exactly what would be displayed if I went to that directory and there were no index.html.

I hope all this is clearer than mud.

Any suggestions?


One “work-around” for doing what you suggest would be to use the PHP programming language and write a php file that just list the directory.

That file can then be called using a redirect, meta-refresh tag, or an .htaccess handler for the index.html to either load the .php file (redirect or meta-refresh method), or parse it as a PHP file (.htaccess method).

There are lots of code snippets out there (google!) to do this in PHP, some simple, some more sophisticated.

At it’s simplest (to me), you could create the following two files, and place them in your directory:

  1. index.html -contents follows:


Directory Listing - <? /******************************************************************** * function that reads directory content and * returns the result as links to every file in the directory * * toss it into any directory and get a list of links to every file * * This program is free software licensed under the * GNU General Public License (GPL). * *********************************************************************/ function directory($result) {

while ($file = readdir($handle)) {
if ($file == “.” || $file == “…”) { } else { print “$file
”; }


return $result;

Select the file you want to go to:

<? echo directory($result); ?>

  1. .htaccess - contents follow

AddType application/x-httpd-php .html[/code]
Doing this will list each file in the directory as a link to itself. Granted, it doesn’t show all the info (Date/time/filesize, etc) that a “raw” index listing does, but you get the idea.

Other code snippets out there do more; just find one you like the output of, or write your own, and go from there.

Of course, this presumes you have no problems below in the directory tree with .html files being parsed as .html

There may/probably are other ways to do this; this is just what popped into my mind first. Good Luck!