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.
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.
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.
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 comment
Glad it worked for you Jason! I’ll check my facts on the taxonomy.Link to comment
Thanks for your guidance Rob. Massive time saver.Link to comment
Glad I could help Nicholas! If you don’t mind me asking, What kind of app are you working on?Link to comment
MoodApp.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?).
CheersLink to comment
Also, 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).
CheersLink to comment
So, 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 firstname.lastname@example.org email accounts still work (through Dreamhost).
Will the approach you outlined here work for my needs?Link to comment
Yep, this should work fine for you David, since ftp is just another sub domain.Link to comment
This was really helpful. Thank you.Link to comment
No problem Barrett. Glad it helped. What are you building on Heroku?Link to comment
This 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 comment
Very cool. We do as well! Drop me a line if you ever want to team up on something.Link to comment
I 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 comment
Do you still see the section to add a custom DNS record Greg?Link to comment
Super 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 comment
Great! I’ll add an addendum to the post.Link to comment
@GregLink to comment
I 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 comment
Hey Lionel. Yes, you’ll need to move your domains so they are hosted by Dreamhost.Link to comment
Thank 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 comment
The steps for apex domain redirecting should be in the last paragraph of the post Lionel. Thanks!Link to comment
Hey 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 comment
Hey Rob,Link to comment
Great 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?
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 comment
Hi 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:
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 !
AkberLink to comment
Heads up everyone in 2018, Heroku has a new DNS url to point to: https://devcenter.heroku.com/articles/automated-certificate-management#troubleshootingLink to comment
Thanks for the update Najeeb!Link to comment