Apache Catch-all Default Site

Are you running several name-based virtual hosts on the same Apache server? If so you need to be aware that it can cause problems if there is ever a DNS record pointing to the server that is not also configured as a virtual host.

The reason for this is that by default Apache will send unmatched requests to the first site found in the configuration. This sounds like a good fallback until you realize that in practice the first site in configuration files is a rather arbitrary choice and also that the result is duplicate content!

Duplicate content is bad for SEO so you should really try to avoid it. As an example if you have example1.com setup as a site in your Apache configuration and also example2.com is setup in the DNS records – Apache will serve the exact same content (from site example1.com) to both example1.com and example2.com visitors!

Not only that but at least in Google Analytics it can distort your statistics as when this happens it will sometimes show as if example2.com is a referrer for visitors to example1.com when in fact is was simply because Apache served example1.com content to example2.com visitors.

Fortunately it is really easy to avoid when you know to look for it. What you do is simply to add this code in your httpd.conf file :

<VirtualHost _default_:*>
   DocumentRoot /var/www/html
</VirtualHost>

In this case the site in /var/www/html is shown when no virtual host matches in the hostname. This is where the default Apache site is stored so visitors will get a generic welcome to Apache page.

One important detail is that this section needs to be before the “Include conf.d/*.conf” line as otherwise it will not be the first site in configuration and you have not solved anything.

Leave a Comment