Web Server

Set DirectoryIndex using .htaccess

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.

[cc lang=”apache”]
DirectoryIndex home.php
[/cc]

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:

[cc lang=”apache”]
DirectoryIndex home.php index.php index.html
[/cc]

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.

Shares:

Leave a Reply

Your email address will not be published. Required fields are marked *