Netlify redirect for multiple folder structure?

I am pushing prebuilt static files to netlify and my folder structure is like
|
---- Client
---- ServerAssets
---- FrontAssets
---- ThirdPartAssets

I would like to serve SPA that’s inside Client so my redirect rule is like

[[redirects]]
  from = "/*"
  to = "client/index.html"
  status = 200

On this redirect rule, the assets inside client are trying to get from root like /static/bundle.js, but it’s actually inside client so I can add rule like the following, this solves that problem

[[redirects]]
  from = "/static/*"
  to = "client/static/:splat"
  status = 200

But when I access a service-worker.js that resides under client root will fail. Because the above rule only applicable for assets inside static, So I found another fix.

[[redirects]]
  from = "/*"
  to = "client/:splat"
  status = 200

But I have to replace the above first rule of serving index.html for the app.

Any way to achieve this?

I need to access client/service-worker.js as domain.com/service-worker.js that resides in the root of client and serve client/index.html for domain.com

Hi, @captainzero, and welcome to the Netlify community site.

Redirect rules are triggered in the order they are listed. We recommend putting the most specific rules first. If URLs don’t match the specific rule, they will keep trying down the list until match something or the end of the list is reached.

My recommended solution would be to put a redirect like the one below before the client/:splat rule:

[[redirects]]
  from = "/service-worker.js"
  to = "client/service-worker.js"
  status = 200

This is a specific rule just for the service worker and should appear before the more general splat rule. If that doesn’t work (or even it if does) please let us know. :slight_smile:

1 Like