GitHub Pages https/www Redirect
GitHub Pages handles redirection between the apex domain and www
subdomain automatically as long as you configure the DNS records correctly.
From the GitHub Pages documentation on configuring an apex domain:
If you configure the correct records for each domain type through your DNS provider, GitHub Pages will automatically create redirects between the domains. For example, if you configure
www.example.com
as the custom domain for your site, and you have GitHub Pages DNS records set up for the apex andwww
domains, thenexample.com
will redirect towww.example.com
. Note that automatic redirects only apply to thewww
subdomain.
While the docs discuss redirecting from the apex domain to the www
subdomain, the reverse direction works as well.
If the apex domain is the desired target (as in this question): set the custom domain value to just example.com
.
If the www
subdomain is the desired target: set the custom domain value to www.example.com
.
Again, this works as long as DNS records are correctly configured for both the apex domain and www
subdomain, as described in the docs.
Not the point of this question, but the question When should one use a 'www' subdomain? offers some good insight on using the www
or not.
What worked for me:
Change your custom domain to be prefixed with
www.
, like this:Save the settings and wait until www.example.com resolves and works.
Remove the
www.
prefix and save again.Wait for browser and DNS caches to invalidate.
All combinations should lead to https://example.com/ and no SSL error should appear.