Single repo, Single domain, Multiple subdirectories

Hi,

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.

I would appreciate any help.

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 :slight_smile: 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:

mywebsite.com

# 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

mywebsite.com/myproject1

  • deploys on project-1.netlify.app from github.com/emma/website repo
  • be sure to deploy to a subdirectory, not the root of the project, as described here
# netlify.toml
[build]
base = /myproject1
// build command for myproject1 directory 
command = "webpack" 

mywebsite.com/myproject2

  • deploys on project-2.netlify.app from github.com/emma/website repo
  • be sure to deploy to a subdirectory, not the root of the project, as described here
# netlify.toml
[build]
base = /myproject2
// build command for myproject2 directory 
command = "webpack" 

… and repeat for /blog. Let us know if that helps or if you have questions along the way!

Hi @jen,

Sorry for the late reply.
Thanks a lot for your support!
I chose the second method and it seems to work fine :slight_smile:

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 :raised_hands:

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 :slight_smile: