How to Set Up A Custom Domain on Heroku
For this post, I’m going to use DreamHost as the domain provider. This process is usually similar for other domain providers as well.
Step 1: Purchase Domain
The first step is to purchase the domain. I use DreamHost for my domain purchases.
Step 2: Point CNAME
- Log in to DreamHost
- Click on Manage Domains
- Click on “DNS” of the domain you want to use
- Under “Add a custom DNS record to [your domain]:”
- Type in “www” for Name
- Select “CNAME” for Type
- Type in your Heroku app URL (example.herokuapp.com) for Value
- Click “Add Record Now!”
Step 3: Redirect Root Domain to WWW
This step is necessary to redirect anyone trying to reach your root domain.
- Go to Manage Domains
- Edit your domain
- Under Redirect, redirect your-domain.com to www.your-domain.com
Step 4: Add Domain to App
Next you will want to add the domain to the Heroku app. You can do this from the Heroku web panel or the command line.
From the command line:
$ heroku domains:add www.example.com
Step 5: Wait
Don’t stress out. It usually takes a while before things start to work because of DNS propagation or whatever.
If you don’t want to use a subdomain, and would prefer root domain, example.com vs www.example.com, you would would have to go with another DNS provider like DNSimple and use the ALIAS record type instead of CNAME. Though it is more expensive because of monthly fees.