Apache, Virtual Hosts & Subdomains

I was trying to setup a subdomain on this website. After reading countless articles and forum posts on how to do it, it just wouldn’t work! No matter what I typed as subdomain.villocq.com, it would always just redirect to www.villocq.com!

The answer: You need to make sure the following is true:

1) Set CNAME records of your subdomains to point to your main domain

2) Configure apache in httpd.conf (or any of the main apache config files) to include AT LEAST this information:

NameVirtualHost *:80

 

<VirtualHost *:80>
ServerName www.villocq.com
DocumentRoot /var/www/home
</VirtualHost>

 

<VirtualHost *:80>

ServerName subdomain.villocq.com

DocumentRoot /var/www/subdomain
</VirtualHost>

It’s critical that the first line is included. Without this, it just would’t work. Once it was in, everything worked perfectly!