DirectoryIndex is specifies that which file the Apache server use as index for the directory listing.In simple words, DirectoryIndex is used to set the defalut page on the Apache server
.
Default page is the page which is rendered when you type domain name or url in browser where URL redirects to the document root directory which will serve the default file set in the Apache configuration.
You can specify multiple index file
names in the DirectoryIndex directive.Here I am going to explain how to set DirectoryIndex using .htaccess file.
Let’s see the SYNTAX of DirectoryIndex directive
1 2 3 | DirectoryIndex [file1, file2, file3 ..] |
DirectoryIndex command will tells the server that to check any of listed file exists,if file is found on server,it should return to the webclient.
Most of the Web servers have index.html as default file but if you are using a shared server, you don’t have access of Apache configuration so you have to configure DirectoryIndex using htaccess file.
You can set DirectoryIndex by writing following line of code into htaccess.
1 2 3 | DirectoryIndex welcome.htm index.php index.html |
After placing above code in your htaccess file you server will search welcome.htm first,then index.php and then after it will check existence of index.html.
Listing of many files create problems because server have to look for many files existence which could make server slower.
Recommended Read:
To set Expire Headers using .htaccess
Password protection with htaccess
Hope this article helpful to you.As always, thanks for reading an article. Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.