Building BobSmithPhotography.net has stopped expanding because I've been overwhelmed with spam on the comment forums. So, if you're here and have questions about web design come and visit Forums, Blogs, Wikis dot com. It has articles that I've written, some of which are also here, and a web design forum as well so you can ask any questions you may have. There is still a lot of good stuff here though, so poke around the links and take a look.

Home » Other Tips » .htaccess » Changing the Default File

Changing the default file

When you browse to a site the server may give you a default file.  For example, if you go to bobsmithphotography.net and do not put a file on the end the server will give you the file index.php.  My server is set up for this.  But what happens if you don't want index.php to be served.  What if you want default.html to be served instead.

Most Apache setups have multiple files already defined as default - index.htm, index.html, and index.php are usually already listed and should work without changing this setting.

Let's look at the following code.

DirectoryIndex page.html

This causes Apache to use page.html as the default file name instead of index.html (.htm, or .php).  You can list multiple files if needed and they can be in subdirectories.  Both the following commands are legal.

DirectoryIndex page.html page.php whatever.shtml
DirectoryIndex /cgi-bin/whatever.cgi

When you list more that one file they will be attempted in order. For the first line Apache will first look for page.html.  If it is not found it will look for page.php.  Whatever.shtml will only be opened if the first 2 don't exist.  If none of the index files are found then a directory listing will generally be displayed.  

 

Content managed by the Etomite Content Management System.