Search code examples
githubgithub-pages

Github Pages with single custom subdomain for multiple repositories (using paths)


I have multiple Github Repositories. By all of them gh-pages are enabled, and the repositories are accessible via paths for example:

  • username.github.io/repository1,
  • username.github.io/repository2,
  • ...

Now I'm trying to create a custom subdomain docs.foo.tld and to have all my repositories gh-pages to be accessible via

  • docs.foo.tld/repository1
  • docs.foo.tld/repository2
  • ...

I have created a CNAME entry docs.foo.tld to username.github.io

But when I'm adding this custom domain (docs.foo.tld) in repository1 repository settings on github, the gh-pages are directly accessible via docs.foo.tld, not via docs.foo.tld/repository1

How I use all this repositories in the path segments /repository1, /repository2 when using same custom subdomain for all of them.

Also to note, when I try to add this custom subdomain to repository2, I get the exception as the CNAME is already taken.


Solution

  • The CNAME and setting the custom domain should only be done in the .github.io repo.

    Other repos should not contain a CNAME and you should not set the custom domain in the other repositories. Those settings are inherited from .github.io repo and setting them in the other repositories is overwriting the root site.

    Just delete the CNAME records from the project repos, and remove the custom domain from the settings of the project repos. You may need to add the custom domain name back to the .github.io repo, but after that you should be all setup like you wish.