Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to have and resolve to index.html and resolve to index.php? Both index.html and index.php reside in the same directory? I am tried the below configuration and all subdomains resolved to index.html.

<VirtualHost *:80>
  DocumentRoot "/var/www/foo"
  DirectoryIndex index.html

<VirtualHost *:80>
  DocumentRoot "/var/www/foo"
  DirectoryIndex index.php
share|improve this question
up vote 4 down vote accepted

According to the Apache documentation, DirectoryIndex can be specified in a VirtualHost. If you have any other DirectoryIndexes specified, you might try removing them and only specifying within the VirtualHost. Your style of configuration would have to support this, however.

As an alternative, you might consider using mod_alias or mod_rewrite instead. Check out the Redirect functions with mod_alias.

share|improve this answer
mod_rewrite would work well in this instance. You can set logic such that if the host-header is "www." it'll serve one thing and if it is "admin." it'll serve another, but the rest will be the same. – sysadmin1138 Jul 15 '10 at 14:19

An other solution is to set only index.php as DirectoryIndex and make a PHP redir into index.php

if ($_SERVER['SERVER_NAME'] != "") {
  Header('Location: index.html');
share|improve this answer

You don't need the overhead of mod_rewrite for something this simple, and that's not an answer to your question, anyway, which is, why doesn't your setup, as listed, work correctly?

The answer to that issue is that DirectoryIndex is cumulative. Therefore, if you have

DirectoryIndex index.html default.htm

above these configurations in your Apache config file, then having:

DirectoryIndex index.php

results in an effective DirectoryIndex of:

DirectoryIndex index.html default.htm index.php

Now, you could shuffle around the order of things in your config file, but a far-more-amusing option would be to add:

<Files /var/www/foo/index.html>
    Deny from all

inside your PHP-powered VHost, which, since Apache can't read index.html by policy, will cause it to failover to the next entry in the DI list.

Then again, come to think of it, maybe just re-ordering your config file is a better idea. ;)

share|improve this answer

Your Answer


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.