So you have hosted your app on Heroku and you bought a domain name from GoDaddy. Now how would you connect the two? Let’s go over the steps on how to do this. There are a couple different parts.
- Go to the terminal and add the Godaddy domain to your Heroku app. From the command line enter the following (more info here – https://devcenter.heroku.com/articles/custom-domains):
1heroku domains:add www.example.com
1heroku domains:add example.com
- Sign into your GoDaddy account and go to the domains area. Then in the upper left hand navigation, hover over DNS and then click DNS manager. See picture below -
- Then click on your domain name to view the DNS file related to it.
- Then remove all records here except for the NameServers
- Add / edit the CNAME record for “www” to point to your Heroku app domain name like “example.herokuapp.com”. Mine is madpad.herokuapp.com.
- Then you have to set the A host to a specific IP address – 18.104.22.168. This is from the GoDaddy documentation found here.
Now that you have completed this step, once the DNS propagates (it takes like 1-2 hours, but may takes as long as a day), you still can’t reach your app.to reach your app at www.your-domain.com. For example at this point I was able to reach my app at www.madpad.me.
Now let’s configure it so that your-domain.com will also work if you type that into a browser. Now back on the main domain page for your domain (see picture), click on “Manage” under “Domain” right by “Forwarding”.
Then add a 301 redirect to forward your domain to www.your-domain.com. Make sure this is of type -“Forward only”!
Now you should be done! Once DNS propagates, you will be able to reach your app at your-domain.com and www.your-domain.com. Congratulations and let me know if you have any questions.
For further reference check out this Stack Overflow link.