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. A quick search on their help area led to Page Rules, so I quickly created this:
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.