How to configure Google Domains + Heroku w a Naked Domain
Another solution is to use some 3rd party DNS provider like Cloudflare to do this. I just went through this same process. App hosted on Heroku with a domain purchased from Google. Signed up for a free account with Cloudflare and was up and running in about an hour following this guide: https://support.cloudflare.com/hc/en-us/articles/205893698
Things I did:
- Delete DNS rules I had tried adding earlier to Google under "Custom resource records"
- Have just one domain added in Heroku for the root: "myapp.com" (not "www.myapp.com", not "*.myapp.com") which gave me a DNS address like "blah-blah-12345-herokudns.com"
In Cloudflare add two CNAME records on the DNS page:
- CNAME "myapp.com" blah-blah-12345-herokudns.com
- CNAME "www" blah-blah-12345-herokudns.com
- Copy over custom DNS nameservers into Google from Cloudflare
After that now I can go to myapp.com
and it just works. Super stoked because I really didn't want www.myapp.com
.
One cool thing is I had already set up an GSuite account for the domain and when I signed up for Cloudflare it imported all the DNS rules from Google, including the MX records for email so it worked seamlessly.
IMHO, you should:
1/ Set your heroku domain to be http://example.com. All the info are in the Heroku documentation.
Heroku should serve your site using http://example.com.
2/ You need to redirect in Google Domains your http://www.example.com to http://example.com. To do this, you need to set web forwarding in the Google Domain console under the website tab. The documentation is straight forward.
Any http://www.example.com request should be forwarded to http://example.com.
UPDATE
Due to your needs, I am wondering if the best is not to disable the naked to www redirection, have both domain points to your heroku instance and get a SSL certificate for them (using let's encrypt makes things easy).
Here is a tutorial.
I hope this helps!
It's advisable to make the www
subdomain the default here, such that the root/naked domain redirects to www
. This is in line with Heroku recommendations, which states:
For maximum scalability and resiliency applications should avoid using DNS A-records and instead use a DNS provider that supports CNAME functionality at the apex, or use sub-domains exclusively
You can achieve this with Google Domains Synthetic Records:
- Go to the Synthetic Records section
- Select Subdomain forward
- Enter
@
for subdomain, andwww.xyz.com
for destination