How to host multiple Github repos using the same custom domain on Netlify?
Asked Answered
B

1

13

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?

Blades answered 4/2, 2018 at 4:55 Comment(0)
S
20

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.

Swipe answered 4/2, 2018 at 5:10 Comment(5)
I work for Netlify and I could not have said it better. Thanks @Jaiden Mispy!Linden
relative to wjakethompson-dissertation.netlify.com or to the main website?Torto
@Torto if you have already pointed the main domain then just go netlify -->your-repo --> then add domain as subdomain.example.com it will works just fine. netlify will automatically create the dns records for you.Olson
Is there a way to include the sitemap of the second repo in the sitemap of the primary?Heeling
Thanks. I was concerned this would redirect the user (and their URL change), but it appears not to be the case: “When you assign an HTTP status code of 200 to a redirect rule, it becomes a rewrite. This means that the URL in the visitor’s address bar remains the same, while Netlify’s servers fetch the new location behind the scenes.”Gullah

© 2022 - 2024 — McMap. All rights reserved.