10

I know there have been very similar questions asked but both companies changed over time and it's been hard to get a full working solution.

I'd like to have a naked subdomain (mysite.io) but if I have to have www.mysite.io, that's fine too.

So on the heroku dashboard I have :

DOMAIN NAME : mysite.io  DNS TARGET : mysite.io.herokudns.com
DOMAIN NAME : www.mysite.io  DNS TARGET www.mysite.io.herokudns.com

I know I should probably only have one of those active but I'm not sure which...

Then, on the NameCheap dashboard, I have :

EDIT: I have read what seemed like a good answer, here's what I changed, awaiting to see if it's gonna work.

CNAME Record  - www - www.mysite.io.herokudns.com
CNAME Record - @ - mysite.io.herokudns.com

And no redirect

I will update if it works

UPDATE :

Using two CNAME records indeed worked fine, except that users can still connect in HTTP and not be redirected to HTTPS. I probably need to add a redirect for that.

Storm
  • 387
  • 1
  • 5
  • 18
  • Hey man, thanks for your question and update. Helped me alot. Was recently trying to figure this out. @Storm – ali Apr 18 '17 at 10:45
  • 1
    @ali That's great. I would also like to add that I used npm modules to force HTTPS (SSLIFY) and to force 'www' to help with tracking analytics – Storm Apr 18 '17 at 13:55
  • I also had to remove the "URL Redirect" for @ host, which is a default entry in namecheap dns config. Once I did that, along with 2 cnames above, it worked. – Luke W Jul 21 '17 at 19:52
  • 1
    I'm having trouble getting this to work in combination with MX records. If I add the CNAME for the naked domain then my email stops working. It seems I have to choose between email and https for the naked domain. – Maros Dec 17 '17 at 18:50
  • @MarosHluska, having the same issue. Did you resolve this? – user592419 Feb 12 '18 at 15:02
  • @user592419 yes, the only way I could find to solve it was switch to DNSimple (or any other that supports ALIAS records) – Maros Feb 12 '18 at 18:47

2 Answers2

2

If anyone is still having problems and your website opens without HTTPS. There is a line of code in rails applications which you should uncomment. Go to config/environments/production.rb In this file you will find a commented line "config.force_ssl = true". Uncomment this line and your application will always open up with https

Domantas G
  • 21
  • 1
  • 7
0

Combination of two answers above will solve the problem for Rails applications:

Go to Namecheap and add the two following CNAME's:

Type: CNAME
Host: @
Value: www.yourdomain.com.herokudns.com
TTL: Automatic

Type: CNAME
Host: www
Value: www.yourdomain.com.herokudns.com
TTL: Automatic

And then follow second answer: "Go to config/environments/production.rb In this file you will find a commented line "config.force_ssl = true"."

That should do the trick.

Andy
  • 531
  • 1
  • 4
  • 19