how to change default index page in apache

How To Change Default Index Page in Apache

For every website, you will eventually need to change the default index page to the home page of your website/blog. In this article, we will look at how to change default index page in Apache Web Server.


How To Change Default Index Page in Apache Web Server

Here are the steps to change default index page in Apache web server. You can change default index page via Apache Server configuration file, or using .htaccess file. We will look at both approaches below.


Change default index page using Apache Configuration

Apache configuration file is present at one of the following locations depending on your installation:

  • /etc/apache2/httpd.conf
  • /etc/apache2/apache2.conf
  • /etc/httpd/httpd.conf
  • /etc/httpd/conf/httpd.conf

Open terminal and run the following command to open Apache configuration file

$ sudo vi /etc/apache2/httpd.conf

Also read : How to Change Timezone in Apache/PHP

You will see the following lines of code.

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>

Change index.html index.php to your choice of web page (e.g home.html).

<IfModule dir_module>
    DirectoryIndex home.html
</IfModule>

Make sure you have placed this file home.html at /var/www/html/. If you have placed it in a different folder (e.g /var/www/html/product/) then modify the path above accordingly (e.g /product/home.html).

<IfModule dir_module>
    DirectoryIndex /product/home.html
</IfModule>

You can also add multiple index pages to Apache as shown below

<IfModule dir_module>
    DirectoryIndex home.html welcome.html
</IfModule>

Restart Apache web server to apply changes.

$ sudo service apache2 restart

Also read : How to Install mod_security on CentOS 7


Change default index page using .htaccess

You can also change default index page for Apache using .htaccess. Before proceeding, please enable mod_rewrite (.htaccess) in your Apache web server.

Open .htaccess file, typically located at /var/www/html/.htaccess

$ sudo vi /var/www/html/.htaccess

Also read : How to Set Up Virtual Hosts in Apache

Add the following line to .htaccess file to set index page to home.html.

DirectoryIndex home.html

Restart Apache web server to apply changes.

$ sudo service apache2 restart

That’s it. Open browser and visit http://your_server_or_ip and you will see the new page. Replace your_server_or_ip with your domain name, or server IP address.

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!

mm

About Ubiq

Ubiq is a powerful dashboard & reporting platform for small & medium businesses. Build dashboards, charts & reports for your business in minutes. Get insights from data quickly. Try it for free today!