Recipe 4.2 Designating One Name-Based Virtual Host as the Default

Problem

You want all requests, whether they match a virtual host or use an IP address, to be directed to a default host, possibly with a "host not found" error message.

Solution

Add the following <VirtualHost> section, and list it before all of your other ones:

<VirtualHost *>     ServerName default     DocumentRoot /www/htdocs     ErrorDocument 404 /site_list.html </VirtualHost>

Discussion

Note that this recipe is used in the context of name-based virtual hosts, so it is assumed that you have other virtual hosts that are also using the <VirtualHost *> notation, and that there is also an accompanying NameVirtualHost * appearing above them. We have used the default name for clarity; you can call it whatever you want.

Setting the ErrorDocument 404 to a list of the available sites on the server directs the user to useful content, rather than leaving him stranded with an unhelpful 404 error message. You may wish to set DirectoryIndex to the site list as well, so that users who go directly to the front page of this site also get useful information.

It's a good idea to list explicitly all valid hostnames either as ServerNames or ServerAliases, so that nobody ever winds up at the default site. However, if someone accesses the site directly by IP address, or if a hostname is added to the address in question before the appropriate virtual host is created, the user still gets useful content.

See Also

  • Recipe 4.4



Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net