Dynamically setting _redirects contents

Right now I’m trying to have my redirects handled by Contentful, the applications builds on install and this creates, and writes to a _redirects file. That said, even upon successful compiling and correct console printing of the expected redirects, it’s not recognized.

The deploy view just reads back that 0 redirects found and - as expected but not desired - the redirects definitely do not work.

When I type out the contents (or prebuild) to make the _redirects file get pushed into version control, it works as expected.

From what I’m seeing it’s not possible to change the redirects file dynamically and is captured by Netlify immediately.

Just curious to know at what point the redirects should be built (if possible) at deploy-time.

The project is to make a white-label, dead-simple URL shortening tool and you can template clone from GitHub, add your Contentful API data to Netlify Deploy variables, and then edit. So it’s not idea to have to build then push to version control, and avoiding a layer of either data reading/writing past the existing Netlify systems is preferred.

Any ideas, or general input is greatly appreciated!

Not sure what you mean by “dynamically”, @pqt. We need there to be an _redirects file in the root of your publish directory after build. That file is only snapshotted once, after build. If it’s there, we use it. If it’s not, we don’t. Sounds like you’d want to debug what contentful actually does since I’m guessing…not that :slight_smile:

Many people do “build” their redirects or custom headers files during deploy (they are processed at the same time - after your build), and are snapshotted in a static format. So I think you can do what you want, and maybe this codebase will give you some inspiration: