How to change the default directory index page using an .htaccess file

This article describes how to use the DirectoryIndex directive in an .htaccess file to specify which page is displayed when a visitor requests a directory.

Changing the default directory index page

By default on A2 Hosting servers, when visitors go to a URL that requests a directory, such as, the web server looks for a file in the products directory named index.html. If the index.html file does not exist, the web server looks for index.htm and other similar filenames. If none of these files are found, the web server either lists the files in the current directory (if directory index listings are enabled), or displays a “403 Forbidden” error message (if directory index listings are disabled).

You can use the DirectoryIndex directive in an .htaccess file to specify a custom file or files that the web server looks for when a visitor requests a directory. To enable the DirectoryIndex directive, use a text editor to modify the .htaccess file as follows. Replace filename with the file that you want to display whenever a user requests the directory:

DirectoryIndex filename

You can also specify multiple filenames, and the web server will search for each file until it finds a match. Consider this example directive:

DirectoryIndex index.php index.html index.htm

In this directive, when a visitor requests the directory name, the web server looks first for an index.php file. If it does not find an index.php file, it looks for an index.html file, and so on until it finds a match or runs out of files to search.

If you want the directory index page setting to apply to your entire web site, add the DirectoryIndex directive to the .htaccess file in the public_html directory. All subdirectories beneath it that do not have their own .htaccess file will inherit the setting.

More Information

For more information about the DirectoryIndex directive, please visit

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.