Apache2 Subdomain Redirect Fun

Last year I set my son up with his own domain name and learned how to use virtual hosts in Apache 2 to host his site alongside mine. It seems like a long time ago, but for the most part it was a pretty straightforward process and within a couple hours he was up and running. Fast forward to yesterday when I was trying to configure a redirect for a subdomain on my site. I started messing around with my site’s virtual host configuration file and realized an existing redirect softball.keegsands.org now sent the browser to my son’s domain. I blindly hacked away at the configuration file for an hour or so, but since it was almost 70 degrees in November I decided to go outside instead.

This morning I picked up where I left off and started at the beginning and verifying that the DNS stuff was configured correctly. There were a couple differences between our DNS settings. My son’s domain had www set up as an A record, while mine had it set up as a CNAME. It shouldn’t really matter, but for consistency sake I switched mine to have www as an A record. Next I tried to add a new virtual host for my subdomain and that didn’t seem to work and just added an extra level of complexity.

Finally I started reading about virtual hosts and was certain I was in the right place, I just needed to get the configuration correct. During the initial set up I do remember an issue where my son’s site would end up being the default virtual host for all traffic to the Apache server, so I focused on why calls to the softball subdomain weren’t being handled by my site’s virtual host. The problem was with the ServerAlias property for my site was set for only www.keegsands.org, I switched it to *.keegsands.org and it started doing the proper rewrite of the URL.

Hosting my own site has been a little annoying at times, but just having that extra experience messing around at this level definitely makes me happy.