Setting the Default Filename for a Directory or Entire Site






Setting the Default Filename for a Directory or Entire Site

Problem

You need to tell your web server the name of the default page for a given directory or all directories on your web site.

Solution

Add or modify the DirectoryIndex enTRy in your httpd.conf file, or a specific direc-tory's .htaccess file. List the files that should be treated as default pages in the order you wish them to be served:

	DirectoryIndex index.php index.html index.htm index.php3 welcome.html

Discussion

When a visitor to your web site requests a URL without a specific filenamesay, http://yourwebsite.com/news/the web server needs to decide which page to send back to the browser. The file can have any name, and be a static file or one that is dynamically generated. Regardless of how the file is created, if it's missing when requested, then your visitors will see an ugly list of every other file in the directory or, worse, a 403 Forbidden error telling them they don't have permission to access the directory.

For more about denying auto-indexing of a directory, see Recipe 5.5.


As you saw in Recipe 1.4 on server-side includes, the setting that determines the name of a directory's default page resides in the main Apache configuration file, and may be overridden by an .htaccess file. Apache configuration changes listed in an .htaccess file apply to all of the files in the same directory and to all of the files in subdirectories below it that don't have their own .htaccess file.

The line to look for in the configuration fileor to add to an .htaccess filelooks something like this:

	DirectoryIndex index.php index.html index.htm index.php3 welcome.html

The setting can contain more than one default file option, listed in descending order of priority. In this example, the server will look for index.php first, then index.html, and so on down the line.

See Also

Recipe 1.4 on using configuration files to enable SSIs.



 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows