_redirect and netlify.toml redirect doesn work in Nuxt3 ISG [HELP]

hi!
I’m struggling with this strange behaviour.
I setup my redirect in the _redirect file placed in the public folder:
and why not simply: https://mywebsite.netlify.app/* https://mywebsite.it/:splat 301!
and after the build Netlify sees 1 redirect.

I try to navigate in the .netlify.app website but nothing happens.

So I try with the .toml file but it doens’t work too.

I never had problem with the redirect int he nuxt3 version with static and spa generation:
With Nuxt 3 ISG redirect downs’t work for me.

If you have any advice would be appreciated because I would avoid the .netlify.app website indexes.

Thanks and kind regards,

Davide

Is the file called _redirects? (not _redirect)
What are all the rules in the file?
What did you specify in the netlify.toml?

Hi @nathanmartin ,
thanks for replying.

Yes the correct name it’s _redirects (I did a typo) and it contains:
https://zavalight.netlify.app/* https://zavaluce.it/:splat 301!

instead the .toml file:

[[redirects]]
  from = "https://zavalight.netlify.app/*"
  to = "https://zavaluce.it/:splat"
  status = 301
  force = true

Both files doesn’t work despite Netlify process the redirects:

Thanks again and kind regards,

Davide

@DidoMarchet As per the Rule processing order documentation I believe only the _redirects rule would take effect, as it has higher priority.

Since it’s clearly not being applied I’d be suspicious if the “1 redirect rule processed” that it is talking about is actually that rule at all.

Have you tried adding some other harmless rules to the file to ensure that the count increases?

For example you could try:

_redirects

https://zavalight.netlify.app/* https://zavaluce.it/:splat 301!
/test-a /test-b 301!
/test-123 /test-456 301!

Hi thanks again.

I add other two rules but nothing changes :frowning:

The news _redirects in the public folder:

https://zavalight.netlify.app/* https://zavaluce.it/:splat 301!
/test-a /test-b 301!
/test-123 /test-456 301!

And the new count:

The file is correct add int he dist folder after the build.

Really thanks again

@DidoMarchet That’s still a good result though, since it proves that the redirect file you’re editing is in the right place and being processed by Netlify.

Due to the Rule processing order I wouldn’t expect the bottom two rules to work when accessed via the zavalight.netlify.app domain, (since they come after the less specific wildcard based rule), but I would expect them to work on zavaluce.it presuming that it is the same site.

I can’t advise why it’s not working, that’ll be up to a Netlify staff member to confirm, but my guess is that your original statement may be correct and that Netlify redirects don’t “play nice” with whatever Nuxt middleware is running.

The headers do look different on the requests, than standard Netlify requests, and contain:

image

Hi @nathanmartin ,
really thanks again for your time.

I add a provisional redirect using the Nuxt middleware:

export default defineNuxtRouteMiddleware((to, from) => {
  const url = useRequestURL()
  if (url.host === 'zavalight.netlify.app') {
    const nextRoute = `${process.env.BASE_URL}${to.fullPath}`
    return navigateTo(nextRoute, { external: true, redirectCode: 301 })
  }
})

I opened an issue into the Nuxt github too.
If someone of the staff need more info (or That I remove the middleware for testing) I’m here.

Really thanks and kind regards,

Davide

@DidoMarchet, you’re using Nuxt in Edge Functions mode: Deploy details | Deploys | zavalight | Netlify. Edge Functions run before redirects, so all the requests are directly consumed by Nuxt and never hit the Netlify Redirects engine. Either switch to Netlify Functions mode or use your middleware.

Hi @hrishikesh thanks to reply and to confirm.

I solved with my custom middleware.

Kind regards,

Davide

1 Like

glad to hear it! thanks for writing back in.

For me placing the _redirects file in the public folder solved my issue:
public/_redirects

1 Like