Pointing a Dreamhost Domain to Heroku
I purchase all of my domains through Dreamhost. Today, I wanted to point one of said domains to a Heroku app I’ve been working on. This is how I did it.
Heroku Setup
Login to Heroku, then head to Settings > Domains. You can then add each subdomain individually, or add a wildcard in. I’ve illustrated both above.
Heroku recommends against mapping apex domains (ie. robandlauren.com) to your app for a number of reasons. We’ll get around that by redirecting our apex domain to the www subdomain. This way if any users hit that url directly, they will still be able to hit the app.
Dreamhost Setup
For each subdomain you want to setup, configure your DNS with a CNAME record pointing the subdomain to the applicable Heroku hostname. Head to the Dreamhost Web Panel, then Manage Domains > [your domain] > DNS. On the new page, you’ll want to “Add a custom DNS record.” Set it up as follows for the www subdomain:
- Subdomain Name: www
- Type: CNAME
- Value: [your app name].herokuapp.com
You should now be able to hit www.[your domain].com and it should bring up your Heroku app. If not, you may need to refresh your DNS in Dreamhost under Manage Domains, as it may be cached. DH let’s you do this once a day. But what if a user hits your site without the www subdomain? Here’s where the redirect comes in.
To redirect our apex domain, we’ll head back to the Dreamhost web panel. Under Manage Domains, edit your domain. You’ll see a section called redirect. Under there, set your root domain, [your domain].com, to redirect to http://www.[your domain].com. Viola! Now users going to either can use your sweet new app.
Comments (27)
Leave a Reply
This seems to work for me, thanks. I did have to do one thing differently, and that’s instead of “Under Manage Domains, edit your domain”, I went to Manage Domains > Add New Domain / Sub-Domain / Redirect.
Link to commentGlad it worked for you Jason! I’ll check my facts on the taxonomy.
Link to commentThanks for your guidance Rob. Massive time saver.
Link to commentGlad I could help Nicholas! If you don’t mind me asking, What kind of app are you working on?
Link to commentMoodApp.mobi – a product that allows companies to quickly capture the pulse of their employees as they leave the building for the day (ie. How likely are you to recommend XYZ as a place to work?).
Cheers
Link to commentAlso, I should mention I’m now using the same technique for Ninefold as I’ve switched hosting to them (migrated from Heroku to Ninefold for cost and performance reasons).
Cheers
Link to commentSo, similar to this, I have a domain that is registered and currently hosted on Dreamhost. Let’s call it “mydomain.com”. Now I’m moving the website to Ruby on Rails, hosted on Heroku, and I’d like http://www.mydomain.com and mydomain.com to both point to the Heroku app.
However, I’d like to make sure that http://ftp.mydomain.com still points to the Dreamhost account (I’m just going to use DH for file hosting for clients), and also to be sure that my ___@mydomain.com email accounts still work (through Dreamhost).
Will the approach you outlined here work for my needs?
Link to commentYep, this should work fine for you David, since ftp is just another sub domain.
Link to commentThis was really helpful. Thank you.
Link to commentNo problem Barrett. Glad it helped. What are you building on Heroku?
Link to commentThis was for my personal blog. I added an additional domain to the DNS. I have lots of rails apps and utilities on Heroku though.
Link to commentVery cool. We do as well! Drop me a line if you ever want to team up on something.
Link to commentI don’t understand. When I try to update the www CNAME in Dreamhost it won’t let me. It’s listed under the “Non-editable DreamHost DNS records.” Any thoughts?
Link to commentDo you still see the section to add a custom DNS record Greg?
Link to commentSuper helpful! Thanks so much. Also, ditto Jason’s comment about accessing the ‘Edit Domain’ option via Manage Domains > Add New Domain / Sub-Domain / Redirect.
Link to commentGreat! I’ll add an addendum to the post.
Link to comment@Greg
Link to commentI found out that the CNAME has to exist before the redirect does.
So if you have already added a redirect – remove it, add the CNAME to www and then add the redirect back.
This got me too.
In Manage Domains whois nameservers are pointing to Digital Ocean servers (that’s who I was using previously). Top two are nameservers are required(can’t leave them blank). Do I point those back to dreamhost?
Link to commentHey Lionel. Yes, you’ll need to move your domains so they are hosted by Dreamhost.
Link to commentThank you Rob. The DNS is working for www. and any *. subdomain, but it doesn’t find the page for just the domain name (i.e. example.com). How can I redirect example.com to http://www.example.com?
Link to commentThe steps for apex domain redirecting should be in the last paragraph of the post Lionel. Thanks!
Link to commentHey Lionel, Rob —
I was caught up on this issue also. I’ve found that the interface has changed.
While on the “Manage Domains” page, click on the “add” button in the row of the domain you want to modify (not ‘edit’). From there, you can add a redirect from example.com -> http://www.example.com.
Link to commentHey Rob,
Link to commentGreat article. Super helpful. I ran into one problem though. When I visit my domain, http://www.example.com, the URL in the browser turns into my Heroku app’s url, example.herokuapp.com. It seems the CName Record is acting like a redirect. Is there a way to keep my domain name in the browser?
Best,
Ken
You got any solution on this. I am facing same problem. going to my http://www.example.com url changes to example.herokuapp.com.
Link to commentHi Guys, thanks for this post.
I’m having some issues here. Say I have a Heroku app called Example, at example.herokuapp.com. I own example.com. I want ‘beta.example.com’ to point to my Heroku app. I followed the instructions here and added a custom DNS record:
Record: beta
Type: CNAME
value: example.herokuapp.com
I’ve added the custom domain in my Heroku with ‘heroku domains:add beta.example.com’
Yet when I run the ‘host beta.example.com’ command, I receive this response: ‘Host beta.example.com not found: 3(NXDOMAIN)’
It says it would take a while, but It’s been well over an hour… Any tips or guidance? Thanks again for this post !
Akber
Link to commentHeads up everyone in 2018, Heroku has a new DNS url to point to: https://devcenter.heroku.com/articles/automated-certificate-management#troubleshooting
Link to commentThanks for the update Najeeb!
Link to comment