7.2. Making Our Own Indexes
In the last section, we looked at Apache's indexing facilities. So far we have not been very adventurous with our own indexing of the document root directory. We replaced Apache's adequate directory listing with a custom-made .html file: index.html (see Chapter 3).
We can improve on index.html with the DirectoryIndex command. This command specifies a list of possible index files to be used in order.
7.2.1. DirectoryIndex
DirectoryIndex local-url local-url ... Default: index.html Server config, virtual host, directory, .htaccess
The DirectoryIndex directive sets the list of resources to look for when the client requests an index of the directory by specifying a "/" at the end of the directory name. local-url is the (%-encoded) URL of a document on the server relative to the requested directory; it is usually the name of a file in the directory. Several URLs may be given, in which case the server will return the first one that it finds. If none of the resources exists and Options Indexes is set, the server will generate its own listing of the directory. For example, if the specification is:
DirectoryIndex index.html
then a request for http://myserver/docs/ would return http://myserver/docs/index.html if it exists, or would list the directory if it did not. Note that the documents do not need to be relative to the directory:
DirectoryIndex index.html index.txt /cgi-bin/index.pl
would cause the CGI script /cgi-bin/index.pl to be executed if neither
Get Apache: The Definitive Guide, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.