Why use CNAME flattening for apex domains
CNAME flattening was popularized in part by Cloudflare.
We have used CNAME flattening successfully for years with multiple web-hosting providers.
DNS A records are a pre-WWW artifact necessary to resolve the apex domain example.invalid
from www.example.invalid
or radar.example.invalid
.
Implement CNAME flattening
To enable CNAME flattening with your DNS records, first screenshot or otherwise backup your DNS settings. Don’t do this experiment during busy times, better to use on a little-used or test website first to ensure it works correctly with your complete setup.
- Determine the web address your web hosting provider puts your website at. E.g. for GitHub Pages it would be
username.github.io
or at Netlifyusername.netlify.app
- Remove DNS
A
record forexample.invalid
that points to a specific IP address - Add a
CNAME
record pointingexample.invalid
to the server address from step #1
For GitHub username joe
with GitHub Pages site at joe.github.io
, with desired web address example.invalid
: make a CNAME
DNS record with example.invalid
as an alias to joe.github.io
.
Again, you do NOT need A
or AAAA
DNS records when using CNAME
.
Notes
- Cloudflare CNAME flattening article
- You may see some old 2014 blog posts initially complaining about CNAME flattening, but these initial hiccups have been resolved long ago.