10

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?

Jake Thompson
  • 1,721
  • 1
  • 11
  • 23

1 Answers1

17

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.

Mispy
  • 830
  • 7
  • 21
  • 3
    I work for Netlify and I could not have said it better. Thanks @Jaiden Mispy! – fool Feb 04 '18 at 17:04
  • relative to wjakethompson-dissertation.netlify.com or to the main website? – elopio Jan 09 '19 at 05:35
  • @elopio 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. – Kartik Garasia Feb 08 '19 at 10:52
  • Is there a way to include the sitemap of the second repo in the sitemap of the primary? – wingardtw May 07 '19 at 22:09
  • 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.”](https://www.netlify.com/docs/redirects/#rewrites-and-proxying) – ShreevatsaR Jun 14 '19 at 16:20