Changing default index page with .htaccess

Add the following to make first.html your index page

DirectoryIndex first.html

You can also have multiple files as in :

DirectoryIndex first.html index.htm index.html index.php

Here the server will check for files from left to right and use the first one available

So I guess you configuration should be

DirectoryIndex index.php index.html

Since you want ot give more priority to index.php when it is found in a directory


Use Redirections:

You can use Redirect directive (Mod_Alias). Edit your .htaccess file and add this line:

Redirect permanent "/index.html" "/cart/index.php"

Or you can use RedirectPermanent directive. Edit your .htaccess file and add this line:

RedirectPermanent "/index.html" "/cart/index.php"

Use Rewrite engine:

You can use Mod_Rewrite to achieve the same result as the above. Edit your .htaccess file and add these lines:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !cart
RewriteRule "^$" "/cart/index.php$1" [R=301,L]

Further reading about Mod_Rewrite: [1]; [2]; [3].


Smart redirection, using PHP:

Edit your .htaccess file and add these lines:

# Obliterate previous DirectoryIndex order:
DirectoryIndex disabled

# Create new DirectoryIndex order:
DirectoryIndex site-condition.php index.php index.html

Create PHP file, called site-condition.php, which will redirect the initial request to the first existing file according to this order priority:

  1. /cart/index.php
  2. /index.php
  3. /index.html

The content of site-condition.php could looks like:

<?php
        $primary_index = 'cart/index.php';
        $secondary_index = 'index.php';
        $tertiary_index = 'index.html';

        if (file_exists($primary_index)) {
                header("Location: /$primary_index");
                exit;
        } elseif (file_exists($secondary_index)) {
                header("Location: /$secondary_index");
                exit;
        } elseif (file_exists($tertiary_index)) {
                header("Location: /$tertiary_index");
                exit;
        } else {
                echo "<html><head><title>Under construction!</title></head>";
                echo "<body><h1>Under construction!</h1></body></html>";
                exit;
        }
?>

According to this example /cart must be a sub directory of DocumentRoot of the current VHost.

Further reading about used PHP functions: [1]; [2]; [3].