Miguel David |||

How to get multiple domains pointing to GitHub Pages using Cloudflare

I recently created a one-man-company to do IT Infrastructure consulting (I even got some cute business cards!). The name of the company is Curious Elephant and as part of creating the company in Portugal I get free DNS (curious-elephant.pt) and web hosting for a year. So I ditched the web hosting and wanted to simply point the company URL to this website.

What you can learn from this post

  • How not to add multiple custom domains to GitHub Pages
  • How setup domain redirection in Cloudflare

The naive approach

As you may or may not have noticed this is done using Jekyll and GitHub Pages. And it already has a custom domain name (migueldavid.eu) pointing to it.

Naively, I tried simply setting up a CNAME record for curious-elephant.pt to minac.github.io and added the new domain in the CNAME file of the repo. It didn’t work.

The Cloudflare way

As I read on GitHub Pages help and on stackoverflow (where else?), the use case of multiple custom domains pointing to your github website simply is not implemented. One can create a second repo and push the same code to both repos and have a CNAME in each of the repos, but this sounds like a silly approach to me.

But there is DNS redirection magic offered by many domain registrars or name servers. Enter Cloudflare.

For clarity here are the relevant DNS records (the IPs are github’s IPs):

Record type Name Value
A migueldavid.eu
A migueldavid.eu
CNAME www migueldavid.eu

A quick search on their help area led to Page Rules, so I quickly created this:

Page Rule in CloudflarePage Rule in Cloudflare

After a minute or so I could type my new custom domain and come straight to this website.

BONUS: The rule is setup so that if I type in something like curious-elephant.pt/about it seamlessly redirects to migueldavid.eu/about. :)

I hope this helps!

If you find mistakes with these recipes, feel free to raise an issue here.

For a more detailed explanation on the DNS records and http > https redirection, check Andrew Molney’s post.

Up next My MySQL Cookbook Over the years I’ve been accumulating notes on how to do quick operations in a variety of technologies. These have been, up to now, for my eyes Start at 6:30 I’ve never been a morning person. Actually, I come from a lineage of not-morning people. (What do you call not-morning people? Laters? Evening
Latest posts Git: choose your adventure Stop before you’re stopped Today I learned about git and permissions Today I learned about view My git flow Using multiple versions of kubectl on macOS Merging two MySQL (or MySQL compatible) databases in AWS using DMS Inspired Recommendations for Portugal God is dead (and we are suffering from it) Advice to my unborn child: be a plumber and an artist On light and shadow You can usually do more/better than you think you can Upkeep Comparing myself to others Fear, Procrastination. Procrastination, Fear Liberalism and a new system Chores Finding my calm place Turning 38 Privilege Humbling Habits Frustration The miracle of the blank page On being late Love is the base of it all A letter to my dead grandfather Self imposed stress Rent the world Start at 6:30