This article goes through the process of setting up a custom domain for a github pages website.
Pre requisites
This article assumes that you already have a github pages website up and running. Mine is klugjo.github.io.
Create the github CNAME file
In order to use a custom domain, you need to let Github know about it with the help of a CNAME file:
- Create a file names
CNAME
at the root of your website. The file name has to be all Caps. - Inside that file, input your custom domain name without
http(s)://
.
My CNAME file contains:
www.codeblocq.com |
- Commit and push your changes
That is it for the configuration on the github side.
Setup the DNS provider
You can contact your DNS provider for help on how to configure an A record but this is how I configured mine:
The CNAME
record for www is set to klugjo.github.io. The role of a CNAME record is to map a name to another name. Useful when the IP address of the host is not know or not stable.
The URL record is set to http://www.codeblocq.com in order to redirect all traffic to the www site.
Notes
- You can only setup one custom domain in the CNAME file on github. See what are the supported custom domains.
- Read this article if you need to configure an A record with your DNS provider.
- If you still can’t get it right, check out this troubleshooting guide.