The command directoryindex lets you to display a specified default page whenever accessing a directory. Say, for example, if a directory is requested by a visitor on your website, you can set up to load the specified file while accessing the directory (if there is no specified filename in the request done initially). For example, for displaying an ‘index.html’ file instead of displaying directory listings and for loading an ‘index.php’ file instead of an ‘index.html’ file.
For setting up directoryindex, you need to make an .htaccess file by abiding the below guidance and main instructions that include the below code:
Apache Web Server will get the instruction to show the ‘index.html’ file through the above code, wherever .htaccess (or other subdirectory) file contained in the directory is accessed.
You can do a directoryindex set up for calling multiple files by making use of the text below:
DirectoryIndex index.html index.cgi index.php
This code above will instruct Apache Web Server to show the file ‘index.html’ as directoryindex, if that file isn’t there then show ‘index.cgi’, and if that isn’t there then show ‘index.php’.
In case the files specified aren’t there, then Apache Web Server would take back to its settings that’s there by default, either by showing directory listings are not available message, an error message, or showing directory listings for directories and files (we can prevent this and this is discussed in the section ‘disable directory listings’ below in this article).