DEV Community

Cover image for How to redirect your hosted GitHub page to a custom domain
Christine Kim
Christine Kim

Posted on • Edited on

How to redirect your hosted GitHub page to a custom domain

If you have your own domain, and a Github account, you could take advantage of redirecting hosted pages to your own domain.

This article is assuming that you already deployed your GitHub page at yourUsername.github.io

For example, I have a website www.example.com through Google Domains. Below is a screen shot of my custom domain.
Screen Shot 2021-06-04 at 10.33.04 PM

To point your GitHub page to your website, first add to your DNS records the url, CNAME record, and the IP addresses. CNAME means that it's a Custom Domain.

www , CNAME, and 'yourGitHubUsername'.github.io .

Next, add GitHub's IP addresses under the DNS - with an A record. The A indicates that it's an 'Alias'.
As of June 2021, the IPs are

185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
Enter fullscreen mode Exit fullscreen mode

@ , A , and the above IP addresses.
You can double check here.

Lastly, under the Settings tab on your GitHub repo for your site, go to the Pages section.
In the custom domain field, put your custom domain (www.example.com).
It might take a little time for it to load
Congrats, you are now pointing your page to your custom domain!

You can also host pages.
By deploying through Github pages, that are not username.github.io. If you deploy using gh pages, you can add themto your DNS configuration.

For example, if I had www.mywebsite.com, and deployed a page www.mywebsite.com/books
add into your DNS configuration
books , CNAME, and 'yourGitHubUsername'.github.io .

Top comments (2)

Collapse
 
quintron profile image
Quintin Maseyk • Edited

Thanks for the post. Can you please expand on your paragraph here:

For example, if I had mywebsite.com, and deployed a page mywebsite.com/books
add into your DNS configuration
books , CNAME, and 'yourGitHubUsername'.github.io .

I'm interested because we currently host our "blog" website on GitHub Pages.
Let's say I've got a public website which is managed and hosted somewhere else: www.mywebsite.com.
Instead of just creating a custom sub-domain ie blog.mywebsite.com id like to push all the paths which look like www.mywebsite.com/blog* to proxy the GitHub Page.

I would have thought your quote above books , CNAME, and 'yourGitHubUsername'.github.io . only applies that change at a sub-domain level (not path based)?

Collapse
 
xtineskim profile image
Christine Kim

Hi Quintin, I've changed the configuration of my personal site since this blog post, but let me see if I understand your question correctly:

  • you'd like to have paths deployed under your url That's correct- so if you have the src code, then you'd have to add a route and display a different page. My paragraph is miss-leading, I should elaborate more on how the paths carry through! thanks for pointing that out :)