Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect root domain to subdomain with https

My setup are,
- @ redicrect to www.example.com
- www.example.com CNAME to openshift account.
- https redirection is handled in the code.

Working:
example.com -> https://www.example.com
www.example.com -> https://www.example.com

Not Working
https://example.com -> "This site can’t be reached"
- I expect to redirect this to https://www.example.com

Any idea how to do this?

like image 517
Jerome Miranda Avatar asked Oct 30 '22 02:10

Jerome Miranda


1 Answers

The problem with your requirement is that DNS does not actually know anything about the protocol/scheme (either http:// or https://), it only handles the hostname resolution. The part where you redirect from example.com to https://www.example.com, although configured in namecheap DNS console, actually involves a kind of a web server which (when you make a request for http://example.com) responds with 301 Redirect to https://www.example.com - that is a service that DNS providers sometimes transparently offer to make life easier for their customer.

I am not familiar with namecheap offering, but I doubt that it is possible to configurehttps://example.com to https://www.example.com, since that would also have to involve that you somehow upload your SSL certs, but perhaps you can check with their support.

The other soultion might be that in namecheap console, instead of example.com -> https://www.example.com you configure example.com CNAME to openshift account. Then, in openshift you just make sure that your site responds to example.com also, and handle the http -> https redirection in code.

like image 113
Dusan Bajic Avatar answered Nov 08 '22 15:11

Dusan Bajic