Github Pages with single custom (sub)domain for multiple repositories

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

  • username.github.io/project1 ,
  • username.github.io/project2 ,
  • ...

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

  • docs.foo.tld/project1
  • docs.foo.tld/project2
  • ...

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

And when I’m adding this custom domain ( docs.foo.tld ) in project1 repository settings on github, the pages are directly accessible via docs.foo.tld , not via docs.foo.tld/project1

How I use all this projects in the path segments /project1 , /project2 when using same custom subdomain for all of them.

When I try to add this custom subdomain to project2 , I get the exception as the CNAME is already taken.

I don’t think github pages can do what you want the way you’re trying to do it.

You could just merge all the docs into a single repository.

Or you could use your own hosting service and have it do this for you.

Hello and welcome here!

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

This should be sufficient. The special repository named <your username>.github.io is what we call your user site. If you set a custom domain on that repository, all your other Pages sites (project sites) will automatically route on that new domain. Only one repository at a time can be associated with a given custom domain (we enforce the unicity).

You can learn more about the different type of Pages sites here: About GitHub Pages - GitHub Docs.

1 Like

Hello everyone! I’m a few months late to the thread, but I’m attempting the same configuration, and somehow, following your steps leaves me with a 404, in a way I cannot comprehend. I’ll provide the details of what I’ve done so far below, what I’m trying to do (which will be pretty apparent from what I’ve done), and some final questions for things I might want to do sometime in the future.

First, here’s what I have. (I’ve removed specific information like my username and project name from the screenshots even though you could literally just google them so that anyone else with this issue can more easily refer to this thread)

What am I doing wrong?

As a follow-up question, I might, in the future, think about adding new subdomains containing multiple projects to my github (say, python.mywebsite.com/MyPythonProject ), and I don’t see any way to do that under this configuration, even if it works. I am aware that I could merge the website portions of ALL my java projects into one repository and the website portions of ALL my theoretical python projects into one repository, but this would complicate my build tooling every time I do an update, so if it’s possible, I’d prefer to have this set up through github pages.
If this is impossible, I’m curious as to whether that’s just something not implemented or if it’s an actual technical limitation with how GitHub Pages is implemented, since if it’s a technical limitation, I might have to mind related gotchas while workarounding.

Thanks!
-Randall

From the screenshot: you haven’t set your custom domain in GitHub Pages: https://github.com/USERNAME/USERNAME.github.io/settings/pages there is a section: “Custom Domain” - so there you have to provide your java.example.com.

Updating the repository cname through the pages settings puts my website at java.mywebsite.com, not java.mywebsite.com/jMyProject.