Can I have multiple domains pointing to different folders of my repo on netlify?

I have an application on astro using SSG that has a folder call ‘brands’ and under this I have my subfolders for each brand like ‘brand-a’,‘brand-b’,brand-c’ etc…

Is it possible for me to have a ‘brand-a.com’ pointing to just the ‘brand-a’ folder and similarly ‘brand-b.com’ to ‘brand-b’ folder and so on?

Basically I want my app to be ‘domain-agnostic’ and as I build it, I want to offer each of my users their own domain which would point to their own folder… is this possible?

If this is not possible, then some advice would be appreciated for a newbie, on how best to handle an application where the content is common for many ‘users/folders’ but each ‘user/folder’ should have their own domain options, if required.

Regards,
Alim

hi @alimbolar

This is possible! But It’ll depend on how you have things structured.

If each brand folders are output folders, generated automatically on each build then you can set up multiple sites, each one having a different publish directory.

If each brand folders are different repos inside the same monorepo, then you can use our monorepo approach and still have different sites.

If each brand builds from separate branches inside the same repo you could do it with Branch Subdomains (this option is enabled by default if you’re using Netlify DNS or we can enable it for you if you’re managing your own DNS).

Just a few suggestions. Can you share more details about your workflow and how you’re building this?

Thanks!

Hi @gualter

Thanks for the prompt response and update… really appreciate it…:-)…

Frankly all the information was pretty new to me… I didn’t know things like Monoreps existed and it looks like that’s what I would try and do but much later when the project grows a bit…

The ‘Publish Directory’ option was not very clear to me but it looks like I would need to have each ‘brand’ on a separate branch and that’s not what I am looking for…

My site is much simpler… and to give you an idea here’s the overview…

So there’d be a blog data folder with folders having markdown files… the classic JamStack blog type of site… where the pages folder would have the data displayed from the markdown files… However in my case I am trying to have multiple blogs (domains) and a centralised data folder… so the blog data folder and let’s say in the pages folder I have multiple folders displaying the filtered data… now each of these folders in the pages folder needs to be a domain … how do I do this?

Being a newbie, the first thought that came to mind was to try something like this…

[build]
functions="functions"

[functions]
node_bundler="esbuild"

[[redirects]]
from="/api/*"
to="/.netlify/functions/:splat"
status=200

from="https://brand-a.com/"
to="/brand-a/"
status=200

from="https://brand-b.com/"
to="/brand-b/"
status=200

the above code is just a thought and I wanted to know how wrong or right I am in thinking if that’s possible… If that’s not possible please do advise what’s the best way to go about this requirement…

If you think monorepo is the way to go, I’ll look at that in the future… but for now, is there a method to get my basic requirement done in an easy way?

Regards,
Alim

That’s not true. If your application builds a different folder for each site, you can have all on the same branch and a different publish directory.

I’m sorry to say, I’m still not super clear about your structure.

Hi @hrishikesh

Thanks for the prompt response… and my apologies if I was not able to explain the issue in a clearer manner.

Frankly this feature is a revelation for me and I didn’t know it was possible… the word ‘monorepos’ is something I had heard about but never explored… so I am super keen on knowing more about this. However the information online seems to be for those who have a basic understanding of monerepos and me, I am not really clear about the basics.

In any case, let me first clear out my issues… I was able to resolve what I needed with this line in the netlify.toml

[[redirects]]
from="https://brand-a.com"
to="/brand/a/"
status=200
force=true

QUESTION 1
this way my requirement was met for brand-a.com and I think I can do as many brands as I want… or can I? Is there a limit to redirects and domains that I can add to one netlify repo? Please do advise.

This is a super simple and basic astro application with multiple html folders created using Static Site Generation…

Now regaring the PUBLISH DIRECTORY option…

QUESTION 2
is this the same as a monorepo? if not, then can you please explain in simple layman terms what the difference is ?

And then with monorepos, is that a structure where each folder is a different app on it’s own? That would mean that each folder would have it’s own node_modules folder and it’s own package.json?

QUESTION 3
But if that’s the case then how would these apps be centralised? I mean each app would have their own CSS and their own JS … right?
If my understanding of the above is right then other than the fact that the folder structure is maintained in an open manner, there’s really no ‘centralised’ source of truth… is there?

I would appreciate if you could please help me understand how this monerepos thing or the publish directory works… as going forward, I’d like to make the app I have now just one of the many apps in a tree like folder/repo… but I’d like to have centralised option for Styling and Scripts, if that’s possible…

If I was still not able to make my requirement clear, please do let me know and I’ll try again…

Please do advise.

Regards,
Alim

QUESTION 1
this way my requirement was met for brand-a.com and I think I can do as many brands as I want… or can I? Is there a limit to redirects and domains that I can add to one netlify repo? Please do advise.

We do have a limit of 100 names per site, so you’d potentially need quite a few sites with many names apiece. You can link the same repo to multiple netlify sites and cause a build of all in parallel for this use case. Other than that annoyance, this workflow can scale.
If you prefer (or could use) a pattern of “customername.yourbusiness.com” we can accommodate infinite names on a single site, matching that pattern, and this will be far, far easier for you to manage since you will not need to give additional tech support to all of your customers about DNS and SSL configuration, which you are otherwise signing up to do (we do not assist your customers in configuring their hostnames for use on Netlify - you do.)

QUESTION 2
is this the same as a monorepo? if not, then can you please explain in simple layman terms what the difference is ?

monorepo means different things to different people. It’s like “good food”. Some people would consider it one, others wouldn’t. There’s no “standard” for monorepos, so it’s one if you want it to be, and to answer your followup question, there is also no one answer there, you lay things out however you want.

QUESTION 3
But if that’s the case then how would these apps be centralised? I mean each app would have their own CSS and their own JS … right?

That’s what you’re building here, right? Some way to do this? So you’ll have to code it up, perhaps by having some “common” directory that you copy all the files out of into your current-app’s build directory. Sky’s the limit - you do it however you want. There is no one right way.

1 Like

@fool

Thanks for the update…:-)… it’s much clearer now… I assumed monorepos was a standardised format/structure and was trying to understand it… but now that you’ve clarified that is means different things to different people, I kind of get it…:-)…

Can you please let me know how I can do what you’ve mentioned in the quote above? I am not clear where do I start with this. Do I need to do something in the redirects in the netlify.toml file to achieve this? Or do I need to contact you to enable this?

Please do let me know as I’d like to have the option of creating subdomains like brand-a.mysite.com, brand-b.mysite.com, brand-c.mysite.com … each of them pointing to a subdirectory that’s the same name as brand-a,brand-b,brand-c … please do advise how can I achieve this.

Regards,
Alim

hi @alimbolar

We need to enable that option called wildcard subdomains on our end.

Wildcard subdomains can be activated, but there are a few requirements:

  1. The site must be on a Pro or above team.

  2. The DNS must be managed by Netlify OR you need to bring a custom wildcard SSL certificate.

  3. The site should not have any domain aliases or branch subdomains.

  4. The primary domain of the website should be on the same level as the required wildcard domain. For example:

If you need the wildcard to be *.bar.domain.com where * can be your wildcard subdomain, the primary domain must be www.bar.domain.com (www can be replaced with any string).

  1. You need to configure the DNS for the wildcard subdomain even in case you are using Netlify DNS. You can follow the external DNS configuration for subdomains and add a CNAME entry with * as the hostname or any other value that you want. The value of this DNS entry should be the Netlify site address.

Are you willing to upgrade for this feature?

@gualter

thanks for the update… that was really helpful.

I will check the upgrade options and I will surely upgrade when the project goes live. Currently the project is live but on a more testing stage and we are evaluating the future requirements. But it’s really nice to know the options provided by Netlify as otherwise I would have never known.

Thanks again… have a nice day…:-)…

Regards,
Alim

1 Like