Introduction
Tired of seeing your website with the github.io at the end? In this post, you will learn how to replace the Github generated URL to a custom URL
What do you need?
- A Domain
- A Static Website!
Setting up the Custom Domain
First, we will be hosting the main website <username>.github.io
. Assuming you already have a website in a repository named <username>.github.io
and you have already set up your GitHub Page for the same. To configure the GitHub Page to redirect to a custom URL, you need to add a CNAME
in the same repository containing the URL of the Custom Domain.
Now, you need to go over to your Domain Services and add two A Records that Point to GitHub. The Destination IPs (GitHub’s) are:
192.30.252.153
192.30.252.154
Now, if you want www
preceding your Domain Name, add it to your CNAME
file in the GitHub Repository and then come back to the DNS Settings of your Domain. You will now have to add a CNAME
Record with the following details:
HOST: www
VALUE: <username>.github.io
Make sure that there are no /
in the VALUE
of the CNAME Record.
Setting up Sub Domains
Let’s say you want your repository repository1
to have it’s own sub-domain on your website. All you have to do is add a CNAME
file in your repository with the custom URL, for example: repository1.<custom-domain-name>.<domain-extension>
.
Now in your DNS Settings of your Domain, add another CNAME Record with the following Details:
HOST: repository1
VALUE: <username>.github.io
After about 5 minutes, you can access the new URL!