Search code examples
dnssubdomaingithub-pages

How can I redirect a custom subdomain to a github-pages project when the domain itself is set to S3?


I have read several questions about custom domains pointing to a github-pages website. However, I could not find the answer for my case.

  • I have an apex domain (e.g. http://example.com) pointing to an S3 bucket.

  • I have a www redirection to this apex domain.

  • I have an existing organization project website on github pages that I can access using an url like this: http://ORGANIZATION.github.io/blog

I want to access that github-page hosted website using a subdomain, like blog.example.com while keeping my apex set to my S3 bucket.

Most of the answers I found were to redirect the domain apex to http://ORGANIZATION.github.io/ and access to the blog using "www.example.com/blog". It is not what I want.

Since ORGANIZATION.github.io/blog. is not a valid CNAME record, I can no use it as value for my sub domain CNAME record.

Is there a way to use a github pages organization project website with a custom subdomain?


Solution

  • Since it can be complicated to figure this out when not familiar with domain names management, I will try to explain what can be and what cannot be done.

    Every domain name has an apex, i.e. the domain name without subdomain.

    Exemple: http://example.com

    Note that www is a sub domain (http://www.example.com) that you can redirect to your apex.

    With Github-Pages, with an organization account, you can only link the apex or a subdomain to a repo with a name formated as follow: orgname.github.io. You also need to set the domain in the repo settings.

    If you have a repo with a different name (i.e. blog), it can be only available with an URL like this: http://example.com/blog

    This is not what I want. So what I did was to create one organization per subdomain. I hope that it is not considered as an abuse to github-pages terms.

    For example, I create a myorg_blog organization with a repo called myorg_blog.github.io that point to my subdomain blog.example.com. Same thing for the portfolio: another organization with a single repo.

    Then I keep the apex pointing to S3, no changes to make on this part.