0

I'm running Apache and I'm getting really tired of editing hundreds of files which are all named index.html. What I'd like is something like this:

/root/foo
    DirectoryIndex: foo.html

/root/bar
    DirectoryIndex: bar.html

/root/bar/narf
    DirectoryIndex: narf.html

...but automatically, for all of my directories. Is there a way to do this in Apache?

  • httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex would suggest not, but I can't help wondering why you're going about it the way you are... – Andy Smith Dec 20 '10 at 1:00
  • ...at the moment my text editor has five tabs open that are all named "index.html", which is not terribly easy to navigate. I'm not really wedded to using DirectoryIndex if there's a better way to accomplish this. – Ender Dec 20 '10 at 1:43
  • Have you considered using a text editor that allows you to use most of the path name in the tabs? Or not having each directory contain an index.html file that you actively work with? – Andrew M. Dec 20 '10 at 5:12
1

From your comment that you're not wedded to the idea of DirectoryIndex, I bet you could accomplish the same feat with mod_rewrite. Something like

RewriteCond %{REQUEST_FILENAME} !-f               
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^/(.*)/(.*)$ http://mysite.com/$1/$2/$2.html [L]

The above isn't tested, just a general idea that you want to get the entire path and supply the last folder name as the .html file if the requested filename doesn't exist. As I said not tested out for exact syntax for getting the directory path.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.