[Common Issue] Can I deploy multiple repositories in a single site?

answered
#1

Say you have an awesome blog as part of your larger website. But you’ve chosen to have your awesome blog in its own, separate repository apart from the rest of your site content. How can you make this work so that your users have a seamless experience under your hostname? Proxying to the rescue!

Yes, Netlify is built around the “single code base per site” model. But this isn’t to say that you can’t host multiple repositories under a single hostname! The choice is completely yours.

I'll describe a typical workflow for how to do this. In this example, both sites are hosted on Netlify. But the second site can live on Netlify or not, doesn't matter.

Let’s connect your blog with its own repository to your existing Marketing site that has a totally separate code base and lives in its own repository . Your blog will live on the Marketing site (already configured as www.yoursite.com) as https://www.yoursite.com/blog.

  1. Blog content should be published on its own site, but with a special caveat. You’ll want to deploy the blog as a subdirectory of the published site (i.e. not in the root). Since you’ll browse it on https://www.yoursite.com/blog as just /blog/index.html, you’ll want to publish it under /blog (no /index.html).
    So, for example, /assets/logo.png becomes /blog/assets/logo.png. References to assets should look like <img src=/blog/assets/logo.png>, without a leading hostname. You can also reference assets from the main site in this codebase as <img src=https://www.yoursite.com/assets/header.png>
    Another way to accomplish this is to make sure that all of your content has relative paths for all links within the subsite, only: <img src=something-not-starting-withslash.png>

  2. On your Marketing site, you’ll deploy the code as usual, but you’ll add some special configuration to refer to the other site using a proxy redirect. For example:
    /blog/* https://yourblogsite.netlify.com/blog/* 200!

  3. Test the blog site! First you should make sure you can see your blog and that all assets load appropriately. Check those assets you have embedded in the blog site as well as those referenced from the main site.

  4. Test via the redirect! Visit https://www.yoursite.com/blog and make sure that things look like you’re expecting. Assets should still load, but you’re now connecting to the Marketing site, and Netlify is reverse proxying to your second site secretly and quickly - and sending the responses back via that connection to www.yoursite.com.

How are things looking? Let us know in the comments below!

1 Like
Error proxying to deploy multiple repos in single site
Bug in non-trailing slash rewrite
#2

Thanks for the write up on this, I haven’t found much documentation that addresses this use case.

This means that Netlify is not a 1:1 replacement for GitHub user/organization project pages.

The drawback here is the subdirectory caveat:

You’ll want to deploy the blog as a subdirectory of the published site (i.e. not in the root).

This means that if you were to switch to Netlify from GH, then you’d have to go into each project repo and move all of its contents into a new project sub directory – am I reading this right?

UPDATE
I’ve tried the above instructions, but the proxying is not working. See this topic about it.

UPDATE UPDATE
I was wrong, the instructions above DID work for me!
I figured out the real problem was that my _redirects file was not ending up in the built directory like it needs to :man_facepalming: