Forum Moderators: phranque

Message Too Old, No Replies

Precendence of DirectoryIndex on Apache2

Question about the DirectoryIndex precedence on the Apache web server

         

grubesteak

1:12 pm on Jul 3, 2007 (gmt 0)

10+ Year Member



I'm working on a project where I've got an index.shtml file and an index.php file side-by-side in a directory.

My httpd.conf file shows the DirectoryIndex like this:

DirectoryIndex index.shtml index.html index.php index.html.var index.HTM

It's my understanding that with the above order, index.shtml would take precedence over index.html, index.shtml would take precedence over index.php and so on.

What I'm wanting to do is to have index.shtml and index.php in the same directory, but when a user visits www.mysite.com, the index.shtml shows up by default and not the index.php. When I'm done with index.shtml, I'll delete it, which would cause index.php to bump to the top of the list.

However, index.php is overriding index.shtml. Any ideas on how I can get index.shtml to override index.php?

coopster

2:49 pm on Jul 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The server will return the first one that it finds, but that does not necessarily mean it will look for them in the order specified in the DirectoryIndex directive. I couldn't find any definitive documentation stating how exactly this is accomplished/processed, so you may have to pull the source code to see. I'm guessing it looks in the current working directory first, likely in alphabetical order, then follow any other directory specific index options in order given.

grubesteak

2:54 pm on Jul 3, 2007 (gmt 0)

10+ Year Member



Oy vey. Source code? For Apache? That's outside the realm of my support.

"The server will return the first one that it finds, but that does not necessarily mean it will look for them in the order specified in the DirectoryIndex directive. I couldn't find any definitive documentation stating how exactly this is accomplished/processed, so you may have to pull the source code to see. I'm guessing it looks in the current working directory first, likely in alphabetical order, then follow any other directory specific index options in order given. "

coopster

3:32 pm on Jul 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Well I could certainly be wrong in my statement ... it seems I should know the answer to this as I thought I ran through this before myself but couldn't find anything in my notes. If Apache does indeed process the DirectoryIndex in order, then perhaps you have something else fouling things up, such as MultiViews. Disable MultiViews (if it is enabled) and see if the server serves the page you expect.

coopster

3:50 pm on Jul 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



OK, I may stand corrected now ...

Use a complete list of options:

DirectoryIndex index.cgi index.pl index.shtml index.html

where you list the most common choice first.

Apache Performance Tuning [httpd.apache.org]

I don't think we would be told to list the most common choice first unless it had some significance. Check the MultiViews option as stated, I'll bet that is your issue.