GitHub pages are great, https is great, and custom domain is great. But when combining them together, I was having a hard time going through all their manuals to make them work. What I want is simple, to bind my domain (weili.me) with my github pages (weilinear.github.io), and add two subdomains, www will work the same as weili.me, and blog will point to my blog (weilinear.github.io/blog).
An overly simple mental model for custom domain is that that domain is an alias for the actual github page. For example, weili.me ⇒ weilinear.github.io. What it achieves that is through the Custom domain setting in Pages, and under the hood is the CNAME file (e.g. https://github.com/weilinear/weilinear.github.io/blob/master/CNAME). Github page server will figure out which is the right content to show based on the URL it gets as it has those CNAMEs associated with each Github pages.
Here is the less simple if-else condition for APEX domain and subdomains:
- Those APEX domain without subdomain, weili.me could be redirected to my github pages as the A record. A record needs to point to an IP address. So the Github page server address is needed. https://docs.github.com/en/pages/configuring-a-custom-domain-for-your-github-pages-site/managing-a-custom-domain-for-your-github-pages-site#configuring-an-apex-domain-and-the-www-subdomain-variant
- Those subdomain should point to the github pages like weilinear.github.io
- For the project one, configure the subdomain and still have that point to weilinear.github.io
Https have a third requirements, the site couldn’t contain any thing other than A/CNAME records. Those URL redirects won’t work.
Therefore, for my simple site, the following will work when configuring the DNS
Type | Host | Value | TTL |
---|---|---|---|
A Record | @ | 185.199.108.153 | Automatic |
CNAME Record | blog | weilinear.github.io. | Automatic |
CNAME Record | www | weilinear.github.io. | Automatic |
On Github side,
Repo | Custom Domain |
---|---|
https://github.com/weilinear/ | weili.me |
https://github.com/weilinear/blog | blog.weili.me |