Redirect from netlify.app to custom domain is not working on a single website

I have a problem in redirecting a website from the <mysite>.netlify.app URL to the real custom domain where it should only b visible.

I have placed the rules on my netlify.toml configuration file like this

[[redirects]]
  from = "https://stefanobartoletti.netlify.app"
  to = "https://www.stefanobartoletti.it"
  status = 301
  force = true

while the same configuration is working on another website, like this

[[redirects]]
  from = "https://bricks-docs.netlify.app"
  to = "https://bricks.stefanobartoletti.it"
  status = 301
  force = true

As you can see, https://bricks-docs.netlify.app correctly redirects to my custom (sub)domain, while https://stefanobartoletti.netlify.app can still be accessed.

From what I can see, the configurations are the same, but on the first site apparently something goes wrong.

Can somebody help me fix this?

You’ve a 404 redirect before the 301 redirect

Removing that should fix this.

That redirect was not set by me, the only one that I’ve configured is the one on my netlify.toml, as I have reported in my previous post. I do not have a _redirects file in my config so it must come from somewhere else.

I’m using Nuxt 3, if this can help.
Maybe somebody else has already experienced this and has a way to solve it.

Then add that and move your redirect from netlify.toml to there.

Thanks for the suggestion, even by moving the redirect rules from netlify.toml to _redirects, the problem is still here, the redirect are not in place in the published site

Ok I managed to find a solution, it was documented on the documentation of Nitro, the engine powering Nuxt, and not on Nuxt doces themselves.

The custom _redirects must be placed inside the public folder and not in the project root, now it works correctly, now https://stefanobartoletti.netlify.app redirects to the primary domain

@stefanobartoletti great, thanks for sharing the answer! :slight_smile: