I’m getting the usual 404 Page not found error when refreshing the page on my react app. I placed netlify.toml file at the root of my repo containing:
[[redirects]]
from = "/*"
to = "/index.html"
status = 200
[[redirects]]
from = "/admin_api/*"
to = "https://staging.myapiurl.com/admin_api/:splat"
status = 200
[[redirects]]
from = "/v1/query/*"
to = "https://staging.myapiurl.com/v1/query/:splat"
status = 200
Please note that I’m using monorepo, and netlify.toml file is in the root of the repo, though I’m building from subdirectory. API redirects doesn’t work as well.
Could get this working by generating _redirects file. But still would like to know why it wasn’t working. It’s frustrating that I had to spend a day in this.
@almas, with the new monorepo support, if a base directory is declared (other than the base of the repo itself), then Netlify changes to that directory and - here’s the catch - it restarts processing from that directory.
This means that when post processing occurs, Netlify will not read the redirects configured in the netlify.toml in the base of the repo - even though it did read that file to change into the new directory for the build processes.
This is because the base setting is read during pre-processing and redirects are read during post processing. This is new behavior introduced by the new monorepo support and we are looking at improving how this is handled.
The workaround for now is the one you have discovered, to include the rules in a _redirects file in the publish directory.
I understand that troubleshooting this on your own was less than ideal and we thank you for creating this forum topic. Hopefully, other people will find this forum post and benefit from your experiences by finding the solution for this here.
As always, if there are any other questions about this - please let us know.
Thanks for answer. The reason I went with toml file instead of _redirects one, is I want to have different _redirects depending on the environment (production/staging branches). Currently I’m using this workaround in webpack.config.js:
I had the same issue and was completely perplexed because I have pre-existing projects that rely on the pre “monorepo support” behavior.
So far, this cost me 3 hours because this is effectively impossible to debug without knowing what you shared @luke.
Now I have to waste more time to go fiddle with webpack and a _redirects file.
On top of the fact that the “monorepo” update is actually misleading and incomplete, I am utterly disappointed with netlify, a service that I had heretofore come to love.
I’ll make sure these concerns get voiced re: monorepo support - but I’m curious as to why you’re thinking that monorepo is misleading and incomplete? If there are things we hadn’t considered, I’d love to add them to the list, if feasible.
It’s been awhile since anyone did this, but I believe you can do this using either frames or iframes, although you could also (thanks to Netlify) have two sites built off of the same git codebase, but with different URLs. You would have to use relative links among the pages and other assets on your site, but it this should be trivial.
Yeah, frames have been deprecated and iframes are useful but not universally so.
Back in the olden days, some registrars used to offer the ability to do URL masking (AKA URL cloaking) so you could render other domains as if they were your own domain. I don’t know if any still offer this, and at any rate it’s bad practice, but for a temporary transition it might help … assuming your registrar supports it.