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.
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
So, for example,
/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
Another way to accomplish this is to make sure that all of your content has relative paths for all links within the subsite, only:
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!
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.
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!