Is it possible to create rewrite redirects via netlify.toml?

I’m seeing this common issues thread: [Support Guide] Direct links to my single page app (SPA) don't work and that is basically my exact issue.

That thread suggests using a _redirects file. If that’s necessary, I’ll try that. But, the docs for redirects seem to suggest that you can instead configure your redirects in your netlify.toml. I might be misunderstanding something, I’m very new to netlify. I was hoping I could keep all my netlify-related configuration in the netlify.toml, so I was hoping to get that working. It seems to have no effect.

Here’s my example:

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

The redirects snippet is copied from the large sample configuration file here: File-based configuration | Netlify Docs

In my builds (example), I see that it says “This deploy did not include any redirect rules”.

Should I just use the _redirects file if I want to do a rewrite-style redirect?

For what it’s worth, I’ve just switched to _redirects and it works fine, but I’d certainly appreciate clarification on the question all the same.

hey there, that’s an interesting inconsistency. Thanks for keeping us updated, we’ll take a look!

1 Like

No problem, looking forward to hearing any updates :smiley:

1 Like

Hi, @maxjacobson, we are working on getting this issue clarified in our documentation.

The issue here occurs when there is a [build.base] directory set. This “restarts” the build process in this base directory.

However, this has a side effect of the netlify.toml file not existing in that new directory. The redirects are not processed when the build restarts there because there is no netlify.toml in the base directory.

Would you be willing to try making a symbolic link to the netlify.toml in the base directory pointing to the copy in the base of the repo? If this doesn’t resolve the issue, please let us know.

Hi @luke, thanks for following up. Hm. Did I do this right? Try out a symbolic link by maxjacobson · Pull Request #31 · maxjacobson/bluff · GitHub

I think it may not have worked, as I’m still getting a 404 in the deploy preview here: https://5ea8acaa8f83770006b5479c--bluff.netlify.app/profile

Hi, @maxjacobson, I do see the netlify.toml file included for that deploy. The netlify.toml file used though does not contain the redirects though.

If you add the redirects to that file, it should work now.

You can also use a second netlify.toml file there if you prefer (instead of a symlink to the netlify.toml in repo base directory).

Ah, of course you’re right. I forgot that part. Well, I think for now I’m just going to stick with the _redirects file after all, since it’s working very well. I appreciate the help!

1 Like