Is it possible to deploy multiple repositories to the same domain?

If I have four GitHub repositories which I would like to deploy to various folders on my domain (e.g., one deploys to root, the others deploy to folders) is it possible?

If so, how do you prevent the root deploy from erasing subfolders?

You can’t do that directly, but this article shows the workflow you’d need to deploy multiple different netlify SITES and host them under subfolders of a single domain:

Thanks @fool and sorry if that Common Issue article is responding to this question, but I can’t manage to see how.

I have a similar setting to that proposed by @brenton. Specifically, this is what I would like to accomplish in my case:

  • The site I want for my root domain (name.tld) is a Hugo site hosted in its own GitHub repository (NOT the personal GitHub Pages one). This works fine.
  • I want to use just GitHub Pages to publish my other GitHub repositories (this is in order to simplify the workflow/workload). For this:
    • I can NOT set any custom domain for my personal GitHub Pages repo (username.github.io), and then all my repos are accessible through username.github.io/reponame
    • BUT I would like to use my custom domain name.tld for this, and be able to access them through name.tld/reponame
    • However if I set up my domain name as custom domain for my personal GitHub Pages repo (which is how GitHub uses it to serve all other repos as subdirectories),
      • GitHub complains that it is not set up correctly (obvious, because it is pointing to Netlify that deploys the main site from a separate repository), and
      • trying to access them through name.tld/reponame does not work, it returns a 404 page from the Netlify-deployed Hugo site, but
      • trying to access them through username.github.io/reponame doesn’t work either, because my personal GitHub Pages site has a custom domain set up.

And this is how I am stuck at this. I would love to have a setup that allows me to

  1. Deploy the root hugo site in name.tld from a GitHub repository with Netlify, and
  2. have all other repositories (with published Pages) load as subdirectories of the main domain straight away.

So my first question is: is this possible? And how?

If the answer is no, I guess my only options are:

  • Somehow tell the main hugo site to load GitHub repos as subdirectories (how?)
  • Forget about having the other repos as subdirectories of my custom domain and just use the username.github.io/reponame URL (which I really would NOT like)

Sorry for the lenghty message. I really hope you could point me in the right direction here!

Thanks in advance.

No need to apologize :slight_smile:

I was suggesting that the article I linked talks about how you stitch together multiple repos under one domain name, which is still my understanding of Brenton’s goal. You’ll have to use the proxying setup mentioned in the article to do this.

I can’t advise you on using github pages as part of the solution, but I guess you’ll want to proxy to them using that same functionality:

  1. configure your domain on netlify.
  2. deploy your other repo(s) on GH pages under a /whatever directory, and proxy /whatever/* to that page from Netlify.

That will accomplish your number 1 and 2 goals. If you don’t see how based on that advice, please provide a real URL that is an example, since I am pretty sure your github username isn’t username :wink: . Then I can give you an example config for that proxying.

1 Like

What made you think my username isn’t username? :stuck_out_tongue_winking_eye:

Your answer really put me in the right path. Specifically the Shadowing bit gave me the aha! moment that helped me get what I wanted:

By default, you can’t shadow a URL that actually exists within the site. This applies to rewrites using a splat or dynamic path segment as well as rewrites for individual routes or files.

Just for the record, in case someone is in a similar situation: I just proxied everything to my GitHub Pages URL with a splat, like so:

/*    https://username.github.io/:splat   200

and it works! Now everything in a URL after my custom domain (except the pages that actually exist on the Hugo site) gets proxied to my GitHub Pages published repositories. This will only be problematic in case I have a page in my Hugo site in a directory with the same name of a repo… which I don’t think will happen very often (and I see as a feature, actually!).

:upside_down_face:

2 Likes

This is great, thank you! The only thing I’m now wondering is if there’s a way to serve up a custom 404. If the Hugo site doesn’t have the corresponding page and there is no GitHub repo with the corresponding name, then this sends users to the 404 at username.github.io. It would be nice if it could instead send users to the custom 404 at the Hugo site on the custom domain, but I can’t figure out a way of getting this to work.

Hi :wave:t6: and welcome to the Netlify support forums. You can set up a custom 404 using a redirect. Please check out our docs page here on how this can be accomplished.

This works normally, but I don’t think this works when using the above solution of having

/* https://username.github.io/:splat 200

in the _redirects file, right? If I place the custom 404 above this, then any directory not found in the Hugo site will give a 404 and never point to the GitHub hosted site; if I place the custom 404 below this, then any directory not found in the Hugo site will try to go to the corresponding .github.io site, which will itself then direct to a GitHub pages 404 if not found.

I guess the issue really lies with how I set up GitHub pages, because what I want is for any non-existent GitHub repository to not give the default 404, but to instead redirect back to the Hugo custom 404.

This is not possible and I’m not sure what your use-case it. Why are you using Netlify to point to GitHub?

I have a main website that is deployed via Netlify to some custom domain. But I want other people in my organisation to be able to simply create individual pages via GitHub that can still be accessed through this same custom domain. The only way I’ve managed to find of doing this is to publish these individual pages via GitHub pages and then using this rewrite solution to fallback to redirecting to .github.io if the URL doesn’t resolve to some directory within the Netlify site.

Okay well, you can potentially solve this issue by using Edge Functions. The flow wlould be something like, for each request, check if it can be served by Netlify, if not, fetch the page from GitHub. If GitHub send a 200, serve that, if not, rewrite back to the 404 on Netlify.

OK, this sounds good, thank you! I don’t know anything about Edge Functions but I’ll look it up. Are there any specific docs you’d recommend?

The official ones should be enough to get started: Edge Functions overview | Netlify Docs

1 Like