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

heroku settings
Heroku settings

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

dreamhost
Dreamhost Web Panel

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:

  1. Subdomain Name: www
  2. Type: CNAME
  3. 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.