How to display directory indexes with the Options directive

If you want to show the content of any of the directories on your hosting account as an index of files and subdirectories, you can do that with the Options Apache directive. You need to add the Indexes option after the directive, so that the whole thing that you should put in your .htaccess file(s) looks like this:

Options +Indexes

When a client requests the URL address of the directory (or any of its subdirectories), the browser will display a simple list of the directory's content.

The plus sign before Indexes ensures that this option is merged with others that are specified in the virtual host file. If you don't use the plus symbol, the Indexes option will overwrite the options in the virtual host file and in .htaccess files that are in parent directories; this will have an effect, for example, on the execution of scripts.

As usual the directive will apply not only to the directory containing the .htaccess file with the directive but also to subdirectories. If in a particular folder/subfolder there's an index file such as index.html or index.php, the directive will not be applied. It's also overwritten by the DirectoryIndex directive; this directive is used to set the default index page. For more information on this check out the article on changing the default index page.

You can include additional formatting to the indexes by using the various mod_autoindex directives. mod_autoindex is an Apache module that's installed on all HostKnox servers. For example, with the following directives:

Options +Indexes
IndexOptions FancyIndexing FoldersFirst
AddDescription "Image Files" .jpg

the content of the directory (and subdirectories) will be shown with FancyIndexing turned on. The FancyIndexing option adds the date and time when the files/folders were last modified, as well as their size. It also allows you to use other indexing options. The FolderFirst option is for listing the subdirectories in the particular directory first and then the files. The AddDescription directive adds a description column to the index. In our example, next to all JPG images there will be a description Image Files.

Was this answer helpful?

 Print this Article

Also Read