I want one subdomain to point to another on the same domain.

DNS Records

Type          Name            Value
A        s1.example.com
CNAME    s2.example.com    s1.example.com

s1.example.com has a valid A record. If I go to s2.example.com I get the server's default virtual host.

What is the correct way to achieve this? Am I doing this wrong by attempting this via the DNS records? Do I need to set up a ServerAlias in the virtual host for s1.example.com instead?

  • The CNAME is working as designed. That subdomain is now pointing at your webserver host. Now you need to configure your webserver to serve the correct content, or issue the correct redirect when it sees requests come in for that host name. Jan 7, 2016 at 20:40
  • @StephenOstermiller What, therefore, is the purpose of a CNAME? Wouldn't it be the same if I forget the CNAME and just add an A record and a virtual host for both subdomains, and point them both at the same directory? Am I correct in saying a CNAME would be useful for pointing to another server's domain but somewhat pointless on the same server?
    – BadHorsie
    Jan 8, 2016 at 10:49
  • 1
    A CNAME serves the same purpose as the A record. It points a domain name (or subdomain) to an IP address. The only difference is that if you already have a record with that IP address you don't have to copy and paste it. It says "point to the same host as that existing A record". It does nothing for redirecting web pages. CNAMEs are useful both on the same server and on other servers. Jan 8, 2016 at 11:08
  • You can use an A record for one of your domains and CNAME for 10 others. It doesn't matter if those ten others serve their own content or redirect. The CNAME records just indicate that they are all hosted on the same server. Jan 8, 2016 at 11:10

1 Answer 1


No. Sorta. It appears, you are, in effect, trying to use DNS as a redirect. That does not work.

If this is what you are trying to do, you will need to add your s2.example.com site to your web server and put in a redirect from one to the other into an .htaccess file or better yet, just map the s2 site file system directory to the s1 directory.

The reason why you are getting a so-called default site, is because if a site does not exist on Apache, it will return the first site created. For some Apache installs, this is a catch-all site. For the others, it is the first site you create yourself.

  • So is it sufficient to add ServerAlias s2.example.com on the virtual host for s1.example.com or should I create a completely separate virtual host?
    – BadHorsie
    Jan 8, 2016 at 10:41
  • Yes. That might work too!! Good thought!
    – closetnoc
    Jan 8, 2016 at 14:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.