# Creating Subdomains with Apache Virtual Hosts | Apache Subdomain Virtual Host Example

### Set Up Subdomains with Apache Virtual Hosts

Some people are unaware that the “www” part of the URL is actually a subdomain (http://www.example.com), and can (in theory) point to a different location than http://example.com - it is not advised that you use www as an active sudomain, as most people expect both example.com and www.example.com to have the same content.

This is actually the basis for canonicalisation, but that’s another blog post altogether

So how do we set up subdomains using Apache virtual hosts? It’s actually very simple, we just need to configure two things, follow this guide for a very simple apache subdomain virtual host example: Apache Virtual Host Configuration File

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27   # Admin email, Server Name (domain name) and any aliases ServerAdmin contact@randoof.info ServerName www.randoof.info ServerAlias randoof.info # Index file and Document Root (where the public files are located) DirectoryIndex index.html index.php DocumentRoot /srv/www/randoof.info/public_html/ # Custom log file locations LogLevel warn ErrorLog /srv/www/randoof.info/logs/error.log CustomLog /srv/www/randoof.info/logs/access.log combined # Admin email, Server Name (domain name) and any aliases ServerAdmin contact@randoof.info ServerName dev.randoof.info DocumentRoot /srv/www/randoof.info/dev/ # Custom log file locations LogLevel warn ErrorLog /srv/www/randoof.info/logs/dev.error.log CustomLog /srv/www/randoof.info/logs/dev.access.log common