How to host multiple Github repos using the same c

2020-05-19 08:37发布

问题:

I am currently hosting my personal website (created using blogdown and Hugo) using Netlify at wjakethompson.com. This is deployed through a Github repository.

I now have a bookdown project in a separate repository that I would also like to host on Netlify, while leveraging the custom domain that I have set up for my personal website.

Currently, this bookdown project is being hosted on the Netlify subdomin (i.e., wjakethompson-dissertation.netlify.com). However, I would prefer to use my custom domain and have this second repo hosted at wjakethompson.com/disseration (preferred) or dissertation.wjakethompson.com. This is basically what Github pages does (hosting a project page as a subpage of the user page), but I have found Netlify to be much easier for hosting my personal webpage, so would like to continue using Netlify if possible.

Is there a way to host a second webpage leveraging custom domain in this way using Netlify?

回答1:

Add a _redirects file in the the main repo containing this:

/dissertation/* https://wjakethompson-dissertation.netlify.com/:splat 200

This tells Netlify to proxy requests through to the other repo. You will however need to ensure that any urls used in the dissertation repo are correctly relative to this path, which may be easy or may be very hard depending on the build system.

The subdomain alternative is simpler and you don't need to do anything special. Just follow the custom domain setup using dissertation.wjakethompson.com and it should work fine. https://www.netlify.com/docs/custom-domains/

The subdomain and main domain do need to correspond to projects on the same Netlify account.