Set DirectoryIndex using .htaccess

  • Avinash
  • 0
  • May 03, 2012
  • Web Server

DirectoryIndex is one of the available setting/directive available in apache. This is use to set the defalut page of the server. Here default page means when you just type your domain or point the URL to any directory then it will serve the default file set in the Apache configuration.

Most of the servers have index.html as default file.

But the thing is that when you are running on shared server then you do not have access to your apache configuration file. In that case .htaccess file comes to rescue. Yes we can override that apache setting using .htaccess file.

You just need to write below code in your htaccess file. Please note that I have mentioned the names as I need, you are free to choose any file.

DirectoryIndex home.php
  DirectoryIndex home.php

After placing above code server will find home.php to serve as a default file. Also you can define more than one files here. You just need to separate the file names with space just like below:

DirectoryIndex home.php index.php index.html
  DirectoryIndex home.php index.php index.html

Most of the servers have index.html as default file.

After placing above code in your htaccess file you server will search home.php first, index.php second and then after it will look for index.html. If none of the llisted files are found then it will throw an 404 Not Found Error.

Subscribe to our feed, follow us and like us to get all latest updates and freebies.

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by: