Notes on Configuring Both Apex and www Subdomain for GitHub Pages
This is about configuring both an apex domain and www subdomain for GitHub Pages. I migrated this site to Jekyll and GitHub Pages previously.
The setup I want:
example.comis the canonical domain in GitHub Pageswww.example.comforwards toexample.com- HTTPS works for both
The steps:
- Configure GitHub Pages in the repository settings.
- Set the custom domain as the apex domain, e.g.
example.com. - In the DNS provider, add a
CNAMErecord forwww-><username>.github.io. Yes, just the user or organization domain. Do not include the repository name. - For the apex domain, add either
ALIAS/ANAMEforexample.com-><username>.github.io, or use GitHub PagesArecords if your DNS provider does not supportALIAS/ANAME. - Set a low TTL while testing.
- Verify
curl -I https://example.comreturns content correctly. - Verify
curl https://example.comshows a redirect - For
www, verifycurl -I https://www.example.compoints back tohttps://example.com. - Enable “Enforce HTTPS” in GitHub Pages once GitHub has issued the certificate.
- Set a higher TTL.
GitHub’s current docs also recommend verifying the custom domain before adding DNS entries. That prevents someone else from attaching one of your domains or subdomains to their repository while DNS is already pointed at GitHub Pages.
Useful checks:
dig example.com +noall +answer -t A
dig www.example.com +noall +answer
curl -I https://example.com
curl -I https://www.example.com