How to change the default index page in .htaccess

Many times you may need to use a different file name for the default index page. Most web servers use a list of default index pages, like index.html, index.htm, index.php, index.phtml etc.

You can easily instruct the webserver to load a specific file via the .htaccess file. Just edit the .htaccess file and add the lines:

RewriteEngine on
DirectoryIndex newindex.html

Now, instead of the default index.html, index.php file, the server will load the newindex.html file. To have a list of possible index filenames, use:

RewriteEngine on
DirectoryIndex newindex.html newindex.php newindex2.php

Note that the above syntax is equivalent with:

RewriteEngine on
DirectoryIndex newindex.html
DirectoryIndex newindex.php
DirectoryIndex newindex2.php

The Apache server will serve the first existing file from the list. It will try to load newindex.html. In case it doesn’t find it will look for the next file – newindex.php – and so on.

If none of the resources exist and the Indexes option is set, the server will generate its own listing of the directory.

DirectoryIndex Directive

Notice that the .htaccess file is a hidden file. If you can’t see it in your file manager then you must enable listing of hidden files.
Show Hidden Files in FileZilla
Show Hidden Files in cPanel

References:
DirectoryIndex Directive

Leave a Reply