Menu Close

How to Change the default Directory Index in Apache Server by .htaccess file ?

The index of a directory can come from one of two sources:

  1. A file written by the user, typically called index.html. The DirectoryIndex directive sets the name of this file. This is controlled by mod_dir.
  2. Otherwise, a listing generated by the server. This is provided by mod_autoindex.

Method 1:- Edit the httpd.conf file

This method can only be done by Server administrator.

This method is suited for someone who uses a dedicated server/VPS. Open the httpd.conf file using a text editor and search for the following line.

DirectoryIndex index.html index.htm index.php


Add the file names at the end of the second line with a space. Take a look at the following example

DirectoryIndex index.html index.htm index.php home.html myname.php jesin.htm

In this way you add all the desired file names. Finally save the file and restart Apache Server. If it refuses to start then check for syntax errors.

Method 2:- Create/Edit .htaccess File

This method is for the most of us who host our websites on a shared server. .htaccess file in your public_html folder.


DirectoryIndex newfile.html index.cgi index.php

The above lines tell the Apache Web Server to display the ‘newfile.html’ file as the directoryindex, if this file is not available then display ‘index.cgi’, and if this is not available then display ‘index.php’.

Test your new configuration by placing a file of the name specified in the DirectoryIndex list.