My website is served as a single git repository. It consists of multiple subdirectories. Each of these subdirectories contain separate build scripts, separate package.json, webpack.config.js, etc.
This is the structure I’m trying to achieve:
mywebsite.com
mywebsite.com/myproject1
mywebsite.com/myproject2
mywebsite.com/blog
Is there a standard way to handle such structure? I’ve read about monorepos and redirects, however I cannot put everything together.
Hey @emma,
There are a few different options for this. This is a nice blog post that outlines one of the more complicated to set up but more elegant and easier to manage ways:
Alternatively, you can go the “easier to set up but less elegant” way This was is to have a different Netlify site for each of your subdirectories. You would deploy each site from the same repo but set the base in your Netlify site dashboard or netlify.toml file to be the subdirectory you want to build. It would look something like this, assuming your github repo is like github.com/emma/website/project1:
# netlify.toml
[build]
// only build homepage
command = "webpack"
[[redirects]]
from = "/project1/*"
to = "project-1.netlify.app/:splat"
status = 200
force = true
from = "/project2/*"
to = "project-2.netlify.app/:splat"
status = 200
force = true
Sorry for the late reply.
Thanks a lot for your support!
I chose the second method and it seems to work fine
I have one more question though.
Since I should set my custom domain only for the main site (if I understand correctly), does this mean that the other subprojects will still be available under their Netlify domains (e.g. project-1.netlify.app)? Is there any way avoid it?
Hey @emma!
Sorry for the delay here. Glad to hear you got your project up and running
If I understand your question correctly, then yes the subprojects will still be available under their Netlify subdomains, and that’s not change-able, but no one will access them that way- the public way that people will access those projects is via your custom domain.
If you’re not able to access them from your custom domain, or if you’re still seeing the Netlify subdomain in the URL bar when you visit those paths, it sounds like we have more configuration to work out. Please let me know if that’s the case- and share your Netlify URL- so I can take a look
Thanks for this! I want to have a standalone eleventy blog deployed on a separate netlify site than my main portfolio site. Then, have the blog be at a subdirectory like ivychen-studio.netlify.app/blog. I should be able to just directly set the base in my netlify site dashboard right?