I had the exact same problem, but with the root account being an Organisation, not a User site (but this makes no difference). The solution is surprisingly simple (I had many trials and errors):
- If not yet done, create the special Organisation/User "umbrella" Site as per the doc by creating a git repository called
myorg.github.io
.
- In the Settings of that repo, under the "Pages" tab, choose your custom domain
docs.mydomain.com
. See picture:
- The content of this repo is up to you. Personally I use VitePress with a small script which deploys at the root of the
gh-pages
branch. The script includes the creation of a CNAME
file at the project root, with the content `docs.mydomain.com'
- Configure your DNS zone with your Internet Provider by adding a
CNAME
entry pointing to myorg.github.io.
(note the trailing dot – your IP may or may not add it automatically for you).
- Return to the Pages Settings of your GitHub umbrella repo, and check that the subdomain is validated (it may take a few minutes).
That's all for the umbrella docs site, whose content contains links to docs.mydomain.com/project1
, docs.mydomain.com/project2
etc.
Now, here is the trick: there is no trick. In all of your real projects, simply deploy your documentation. You can do so in the docs
subfolder or not, in either branch, that is, in the master
or gh-pages
one, it doesn't seem to matter.
If any, the docs/
part of the url will be replaced by project1/
etc. There is no need for a CNAME, and no need for another custom subdomain.
Here is the config of one my project:
See how GitHub indicates under which URL the site is published.
Here is my GitHub organisation and its umbrella site
and the results:
Bonus. If by any chance you configure your projects to have sub-subdomains (that's what I tried before finding the solution) – such as https://project1.docs.mydomain.com
, the above configuration will also "work". That is, navigating to https://docs.mydomain.com/project1
will redirect you to https://project1.docs.mydomain.com
Internet is kind of amazing, isn't it?