Search code examples
sslhttp-redirecthttpsdnscname

How can I redirect a website site with a CNAME record using HTTPS


I inherited a strangely configured website and I'm trying to setup an SSL certificate but with no luck.

Here's the initial setup. There are 3 distinct websites with different URLS. Let's say:

  • site1.com
  • site2.com
  • site3.com

All three websites are hosted on the same web hosting provider (same account) but each with their distinct root folder. site1.com has all the files that are needed to show the website while site2.com and site3.com have the generic default files saying "under construction".

site2.com and site3.com have a CNAME record setup like so:

www.site2.com CNAME www.site1.com

and

www.site3.com CNAME www.site1.com

When I access www.site2.com I am able to view site2's content which is distinct from the other two. The code used in the Content Management System is shared for all 3 sites but the CMS looks at the URL it's loaded from and shows a different layout depending on the domain.

So far everything works.

But when I enable https and visit site2.com or site3.com I can only see the default "under construction page" and not the correct content.

I was thinking it had to do with the domain name and SSL certificate so I bought a multi-domain SSL certificate with all 3 domains and installed it on site1.com since the other sites are kind of mirroring that one.

Even with the multi-domain SSL certificate, I'm still seeing the "under construction" pages when I visit site2.com and site3.com.

I also tried installing the multi-domain on site2.com and site3.com but that didn't do anything also.

Does anyone know why it stops working when I add https in front of site2.com and site3.com?


Solution

  • This problem is not related to CNAME or the certificate. The problem is that the configuration of your web server has no specific setup for site2 and site3.

    A CNAME just helps to resolve the IP address for site2 and site3 to the one from site1. A CNAME is just an DNS level alias for a domain name and the web server does not know about this. This means that the name transferred by the browser to the server is still site2 or site3 and not site1 and thus the server will take the site2 or site3 specific configuration and not the one for site1.

    This means you need to adjust your servers configuration so that the one for site1 will also be used for site2 and site3. How exactly this needs to be done depends on your specific web server. Since nothing is known about this server and its setup no further help about this can be done.