October 26th, 2003

tetrap2

Useful tip for running a web site on an Apache server

Due to someone linking to a non-existant page on my site, I was trying to redirect /index.php to / earlier. This didn't work. The server went into an infinite loop.

Fine, said I, I'll redirect /index.php to /index.shtml which is the actual file I wanted. But then I discovered that that redirected all accesses to / to /index.shtml which is not what I wanted (I prefer leaving the index page off the end if at all possible, to make for a cleaner URL).

The problem was, it seems, because when you request a directory (e.g. http://www.tetrap.com/drwho/) the web server searches a list of possible file names that your index file could be. Evidently, index.php was earlier on the list than index.shtml.

Sticking this in my .htaccess file fixed it:

DirectoryIndex index.html index.shtml

I guess it'll also speed up accesses to directories marginally, as the server will only be looking for those two filenames.
  • Current Mood
    geeky geeky