How to set up a Wildcard (catch-all) Virtual Host in Apache
By marc • May 14th, 2008 • Category: ApacheSuppose that you need to set up a virtual host in Apache that catches all un-matched traffic coming in to your server. There are a number of uses for this, but the main idea is that you have a number of other virtual hosts set up, but you want anything that doesn’t match those to forward to a specific virtual host.
Here is an excerpt from an example httpd.conf file:
-
-
<VirtualHost *:80>
-
-
ServerName default
-
ServerAlias *
-
ServerAlias somepreviewdomain.com
-
-
DocumentRoot /home/me/my_app/html
-
-
<Directory "/home/me/my_app/html">
-
Options Indexes FollowSymLinks
-
AllowOverride All
-
Allow from All
-
</Directory>
-
-
</VirtualHost>
Just be sure to make this the last virtual host entry in your httpd.conf file, so that any other vhosts before that work as they should.
In this example I also included an alias for an actual domain so that the vitualhost can still be accessed by an actual domain as well.