Linking A Custom Domain To GitHub Pages

  1. Step 1
  2. Step 2
  3. Step 3
  4. Step 4
  5. Step 5

Here is a quick guide for adding a custom domain (e.g., mydomain.com) to your github pages website (e.g., username.github.io).

Step 1

Buy a domain, I used namecheap.com, but you can choose any other domain name registries.

Step 2

In your github.io repository’s Setting page, add the domain you purchased in Step 1 to the “Custom domain” input box.

Step 3

In your DNS Management console, add a CNAME record with the following parameters:

  • type = CNAME
  • name = www
  • value = username.github.io.

This tells your DNS to point www.mydomain.com requests toward your github personal website username.github.io.

Also, in your DNS management console, add 4 more A records with the following information:

  • type = A
  • name = @
  • value = IP

For IP, provide the GitHub IP address that host your username.github.io site. As of writing(2023-01-19) these IPs are:

1
2
3
4
185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153

You can always get the latest IP addresses on this GitHub Docs page.

Step 4

Navigate to mydomain.com to see your github page. Be patient if it doesn’t work immediately. This lag is due to DNS propogation.

Step 5

GitHub pages support HTTPS, if you would like the content only be served over HTTPS, you can check the “Enforce HTTPS” checkbox on your repository Setting page.

The next thing we have to do is bring SSL/TLS support to your domain. There are several ways of doing this, normally you can purchase certificates from a trust provider, however, you can choose free service as well. For example, CloudFlare is providing Free SSL / TLS support for your domain. In this case, you need to change the DNS to theirs then they will do the rest for you.

If you are getting too many redirects error, then the issue would be CloudFlare’s SSL/TLS Settings. By default CloudFlare uses a Flexible SSL option, which forces requests between clients and CloudFlare to be sent over HTTPS but allow requests between CloudFlare and your GitHub pages server to be sent over HTTP.

If that option is enabled but GitHub pages server has its own SSL certificate, then your server will redirect these requests to HTTPS and likely cause the too many redirects error. You can resolve this issue by switching to another encryption mode, like Full or Full (strict).