Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

migrated from webmasters.stackexchange.com Dec 20 '10 at 0:28

This question came from our site for pro webmasters.

    
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 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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