By default, Apache looks for index.htm, index.html, index.php, and default.htm to load as default index page for your website. If you want to change the name of default index file, you can do it via .htaccess file in Apache web server. Let us take a look at how to change default index page in .htaccess.
How to Change Default Index Page in .htaccess
Here are the steps to change default index page in .htaccess.
Before you proceed, please ensure you have enabled .htaccess (mod_rewrite) in Apache. Here are the steps to do it:
Place your .htaccess file in the root document folder of your website (/var/www/html) and add the following rules. .htaccess file allows you to change Apache config without actually accessing its config file.
1. Update .htaccess file
Open .htaccess file in a text editor
$ sudo vim /var/www/html/.htaccess
Add the following line to it
#Alternate default index page DirectoryIndex first.html
This will change your default index file to first.html. If you want the server to look for a list of pages as default, you can add them too. Apache will look for pages left to right.
In the above example, we also add index.html, index.htm, index.php to the list
#Alternate default index page DirectoryIndex first.html index.html index.htm index.php
Save and close the file
2. Restart Apache Server
Restart Apache web server to apply changes.
$ sudo service apache2 restart
That’s it! Apache will remove www from domain URL.