Search code examples
herokuhttpscnameovh

Is there a way to redirect CNAME www.mywebsite.com to https://www.mywebsite.com with ovh and heroku


I am hosting my nodejs app in heroku and my domain name is in OVH. I managed to create a subdomain www and a CNAME record that points to my heroku app. It is working fine and SSL is also working fine from heroku. I added a redirection from all subdomains to https://www.mywebsite.com and everything is working fine. My problem is when i type www.mywebsite.com, there is no redirection and no SSL. How can i redirect www.mywebsite.com to https://www.mywebsite.com ? Thanks !


Solution

  • Unfortunately, No.

    DNS maps domain names onto IP addresses, that is, it tells the client that example.com points to 12.34.56.78. HTTP vs. HTTPS is a matter of picking a port, and using the right protocol, and this is negotiated directly between client and server; DNS lookup has already happened before that.

    If you want to redirect all plain-http traffic to https, you have to do it on the web server, not the DNS server.

    In your situation, you could do this in node.js.
    There tons of examples online for node's built-in http server or for frameworks like express. I'd recommend this solution.

    But there are also solutions like Cloudflare.
    They offer you a DNS Service and a proxy, which can handle such HTTP to HTTPS redirection and they even let you use their own SSL Certificate, so you don't need to buy (or let's encrypt) a SSL Certificate on your own, for example.