Skip to main content
  1. Posts/

Multiple Domains on GitHub Pages

Chris Ayers
Author
Chris Ayers
I am a father, nerd, gamer, and speaker.

Something I found out after moving from WordPress to GitHub Pages is that out of the box you can only host a single domain for a repository with GitHub Pages. This is a problem for me because I have a number of domains I was hosting at WordPress that I wanted to point at my GitHub Pages.

Official Docs and the limitation
#

So officially, GitHub pages doesn’t support multiple domains. The docs here https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/troubleshooting-custom-domains-and-github-pages#custom-domain-names-that-are-unsupported state:

Make sure your site does not

Use more than one apex domain. For example, both *example.com* and *anotherexample.com*. Use more than one www subdomain. For example, both *www.example.com* and *www.anotherexample.com*. Use both an apex domain and custom subdomain. For example, both *example.com* and *docs.example.com*.

This means for example, I can setup www.chris-ayers.com and chris-ayers.com for my repository and nothing else. If I want another domain to point to it, like chrisayers.me, I would probably need to fork the repository and setup the new repository for the additional domain.

So how do we solve this? There has to be another way. There is! We can use Cloudflare to redirect the additional domains to the GitHub Pages domain. It seems this has been an issue for everyone since 2018. I found a few articles that helped me figure this out:

Cloudflare
#

Cloudflare is a DNS provider that has a free tier. It also has a feature called Page Rules that allows you to setup custom rules for your domain. This is what we will use to redirect the additional domains to the GitHub Pages domain.

Setup
#

First, we need to setup Cloudflare. This is a pretty simple process. You just need to create an account and add your domain. You can do this by following the steps here: https://developers.cloudflare.com/fundamentals/get-started/setup/

  1. Create an account (if you don’t already have one)
  2. Add your domain
  3. I chose the free plan for each of my domains
  4. I reviewed all the entries and made sure they were correct (I removed most of them)
  5. I updated the DNS nameservers for my domain to the ones provided by Cloudflare

I decided that my primary domain would be https://chris-ayers.com. As part of the normal GitHub Pages DNS setup, you add the domain name to GitHub Pages then add A records to your DNS domain. The directions are here. I’ve added the needed A records to my domain on CloudFlare.

Next I need to setup my other domains. For each domain, I added it to Cloudflare. I then setup 3 CNAME entries. Let’s look at my configuration for chrisayers.dev as an example. I setup the following CNAME entries:

With this configuration, I’m saying that pretty much everything should point to https://chris-ayers.com.

TypeNameContent
CNAME*chris-ayers.com
CNAMEchrisayers.devchris-ayers.com
CNAMEwwwchris-ayers.com

Now I need to setup the Page Rules. These are main thing that makes it all work.

Cloudflare Page Rules
#

This is where it gets a little more complicated. Continuing with my example before, adding chrisayers.dev, I setup the following Page Rules:

The main thing is to note the special characters (*) and variables in the rules.

FieldValue
URL (required)*chrisayers.dev/*
Forwarding URL301 - Permanent Redirect
Destination URLhttps://chris-ayers.com/$2

After a little bit, everything should redirect to the GitHub Pages domain and work. I was fiddling a lot for the first domain or two, and they took a little while to start working. I’m not sure if it was just a propagation issue or what. But after a few hours, everything started working.

The other domains I did (I have around 10) were pretty quick. I think it was just the first ones that took a while because I was trying to figure out the process.

Conclusion
#

I’m pretty happy with the results. I was able to get all my domains to point to my GitHub Pages site. I’m not sure if this is the best way to do it, but it works. I’m sure there are other ways to do it, but this is the way I figured out. I hope this helps someone else out there.

Related

Customizing the Jekyll Theme

I haven’t done a lot with jekyll in the past, but I’m a big fan of Markdown everything. For me that usually means I’m taking notes in Markdown Obsidian, doing diagrams in mermaid in Azure DevOps or https://mermaid.live/. I’ve even started turning my talk slides into Markdown with a tool called MARP. Understanding when I use standard Markdown or some sort of templating language (jekyll uses Liquid) has been fun. I’ll do something in HTML or Markdown, then find out that Jekyll or my theme already has helpers to render that (like gists, videos, and figures). Sometimes rendering more advanced things takes a little tweaking of Jekyll and the theme.

Migrating from WordPress to GitHub Pages

I’ve been hosting on WordPress for a while. I wanted something that worked pretty well and was easy to work with. I picked a decent theme, added some plugins, pointed my domains and was up and running. I would work on blogs in Markdown, and then paste the txt into a Markdown. I could upload a few images and move them around in a wysiwyg. Lately, I’ve been doing a lot more in Markdown. All my conference talks were in PowerPoint but I’ve started switching over to Markdown slides using MARP. I should probably do a post on MARP sometime (I did :-) ). I wanted to reduce my overhead of WordPress Hosting and get back into more direct styling and coding of my theme. I decided to switch my hosting to Jekyll on GitHub Pages.

Validating .NET Configuration

·703 words·4 mins
This blog was posted as part of the C# Advent Calendar 2022. I really want to thank Matthew D. Groves and Calvin Allen for helping set this up! Look for #csadvent on Twitter! Make sure to check out everyone else’s work when you’re done here One of the great things about the configuration system in .NET is the type safety, dependency injection, and model binding. Something we can take advantage of is to validate our configuration on startup and fail if it doesn’t pass validation. Having that fast failure is awesome when working with containers and applications that have liveness and readiness probes.

Presenting Best Practices - Part 1

·940 words·5 mins
Presenting and speaking are skills that require practice to hone. I was a consultant for many years presenting to clients and customers of all levels and sizes. In addition, I started speaking and presenting at meetups, user groups, and conferences. Over the years, I practiced, I read, and I gave a lot of presentations. I’d like to share some of the learnings and best practices I’ve found in that time. I plan multiple posts, starting with Preparation. I’ll have more on slide design, and presentation tips.

Shared Focus - Using The First Way with DevOps

·366 words·2 mins
A common issue I see when discussing DevOps with teams or organizations is the presence of Organizational Silos. Organizational Silos are made up of all types of people. Sometimes its a job type, like developers, qa, or infrastructure. Sometimes its a department, like accounting, or hr. Whatever the composition of these silos, they usually impact organizational performance and the ability to deliver value to end users. This happens over time, with members of the silo identifying with each other, viewing those not in the silos as outsiders. Depending on the business, the silos can lose trust in the business overall and tighten ranks around their silo. The silos can turn into walled fortresses. When the silos get in the way, the silos are more focused on their own success than the success of the organization.