Configuring a Default Name-based Virtual Host


NameVirtualHost * <VirtualHost *> ... </VirtualHost>


As mentioned in the previous section, the first virtual host present in the configuration file will answer requests for domains that are not explicitly handled by other virtual hosts. If you host multiple websites, it can be useful to set up that virtual host so it returns a page that either provides a list of available websites in the machine or explains why that particular website is not recognized. You can do so by placing such a file (default.html in the example in Listing 5.3) in the document root and redirecting all requests to it with an AliasMatch directive. You can achieve a similar effect replacing it with an ErrorDocument directive:

ErrorDocument 404 /default.html


Or you can even send users directly to one of your other websites with a Redirect directive.

RedirectMatch /* http://www.example.com


Listing 5.3. Configuring a Default Name-based Virtual Host

NameVirtualHost * # The section below needs to be placed on top of any other virtual host section <VirtualHost *> ServerName default.example.com DocumentRoot /usr/local/apache/sites/default AliasMatch /* /default.html </VirtualHost>




Apache(c) Phrase Book(c) Essential Code and Commands
Apache Phrasebook
ISBN: 0672328364
EAN: 2147483647
Year: 2006
Pages: 254

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