I currently have 3 different branches in Github (dev/test/prod) and 3 API servers (dev/test/prod) on non-Netlify domains, and I am currently using the Netlify
_redirects file to handle redirection of API calls to these domains. For example, dev would have a redirects file like:
/api/* http://dev.my-api-instance.amazonaws.com/:splat 200
And Test would have a file like
/api/* http://test.my-api-instance.amazonaws.com/:splat 200
My problem is when I create pull requests from one environment to another (e.g. Dev to Test) - these _redirect files get overwritten in the pull request (e.g. /api/* for test starts pointing to dev server) and I have to manually rewrite these files after accepting the pull request.
I would avoid committing the _redirects file in Git, but then Netlify wouldn’t be able to read it. Alternatively, I would use different contexts in netlify.toml to have my redirect rules vary for each environment, but redirects seem to be a special case and can’t be set per-context in this file.
Is there any way I can avoid manually rewriting the _redirects file for each branch merge? I only need to set these very infrequently, but I merge branches often.