WWW subdomain redirects to default site instead of virtual host

apache-2.4mac-osx-serversubdomainvirtualhost

I am hosting multiple websites on an instance of OS X Server 4.0 with an issue. I have a default personal site that is available on the normal domain and the www subdomain. I tried to configure other sites to have that similar result also. However, I am running into a problem. My virtual hosts (other sites) have the www subdomain configured in the DNS records. I configured my Virtual Hosts in OS X Server with 0 additional domains, redirects, or aliases. All other settings are also left default.

The DNS on OS X Server is configured correctly as well. When I try to access http://example.com/ it sends me to the Virtual Host correctly. However, when I do http://www.example.com/ it sends me to the Server Default website, which is my personal site. The only way I can fix this is to add another website using the www.example.com into the list.

Is there another way to fix this instead of adding another site to the list?

Best Answer

Add www.example.com as a ServerAlias to the VirtualHost you want it to use.