Apache

How To Change Default Index Page In htaccess File

DirectoryIndex used to allow you to land default page when client access a directory. For example, when a visitor request a directory to access it on your website, you can define the file such as index.html, index.php, index.shtml etc to load when they request to a directory. For example, to load  default page  “index.html” file instead of “index.php” when client request a directory . Simply you can create a .htaccess file in your web root directory.

In this article I will show you how to change default index page in the .htaccess file. Before doing this make sure you are using Apache web server and you have enabled .htaccess for your virtual host.

Change Default Index Page

Now lets edit the .htaccess file and add a DirectoryIndex entry followed by file name, your .htaccess file will look like below:

# vim /var/www/html/.htaccess

#Default single index page
DirectoryIndex index.shtml

Save and closer file. You an also define multiple index pages like like below:

# vim /var/www/html/.htaccess

#Multiple default index pages
DirectoryIndex index.shtml index.html index.php

Save and close file. Above you can see I have define DirectoyIndex first load default page “index.shtml” than “index.html” and index.php and so on. If index.shtml not found on the web document root then Apache will try to load index.html and so on.

If non of them files are available on directory. Apache server try to revert it’s default setting and it will display an error message like “ 403 Error-Forbidden!” . If you get this error that means Indexing is not allowed on your web server.

Options  -Indexes

Thanks:)

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment