All Posts

Google Domains for GitHub Pages

TL;DR: 301 permanent redirects will list the canonical url as your *.github.io* URL which isn’t great for SEO and google indexing. You need to set up the custom domain correctly on GitHub to point to the URL

When initially setting up this blog on GitHub Pages one thing you get for free is the URL under your GitHub handle namespace which was rjferguson.github.io. This is great for getting a static site up quickly with no fuss. I ended up purchasing rferg.io from Google Domains as well. Not having a lot of time to set things up properly I set a 301 permanent redirect to the rjferguson.github.io with path forwarding so I could quickly start sharing and using my purchased domain. This is all well and good if I wanted to stop there, but of course I want my blog/site/articles to be searchable on Google with the rferg domain easily. Going to the Google Webmaster tool I get below:

Domain not in google

The above image shows 2 things, 1 the rferg.io domain is not in Google, and the canonical reference is the rjferguson,github.io URL. Fixing that is easy enough in a few steps:

  1. Change the GitHub repo to know about the URL in Settings > GitHub Pages > Custom Domain

    • This should commit a file called CNAME to your master/main branch with your custom domain url in it, in my case rferg.io. If it does not you’ll need to add it to add it via a commit.

GitHub Repo Settings

  1. Point your domain to the Github pages

    • Go to your DNS settings and add the following 2 entries
    • The A record should have 4 entries while your WWW subdomain (www.rferg.io) should have 1
Name Type Data
@ A 185.199.108.153
185.199.109.153
185.199.110.153
185.199.111.153
www CNAME rferg.io

Google Domains Records

  1. Check if it works! You should be able to dig the results after a few minutes.

dig www.rferg.io +nostats +nocomments +nocmd

This should return something as follows with the CNAME and A record

; <<>> DiG 9.10.6 <<>> www.rferg.io +nostats +nocomments +nocmd
;; global options: +cmd
;www.rferg.io.			IN	A
www.rferg.io.		300	IN	CNAME	rferg.io.
rferg.io.		300	IN	A	185.199.111.153
rferg.io.		300	IN	A	185.199.109.153
rferg.io.		300	IN	A	185.199.108.153
rferg.io.		300	IN	A	185.199.110.153

After those 3 steps are completed The basic redirection is done and the google console live result looks like:

Live Crawl Results

Gatsby specific things

Two additional things I did was was the plugins gatsby-plugin-sitemap and gatsby-plugin-canonical-urls both of these plug-ins help with setting the canonical URL and generating a site map.