Need a rewrite rule to pass status code but not redirect

I need that when a url under /api/* is matched it will rewrite but not change the status codes passed from the upstream server.

The issue with what I’ve found is that if I add a 200 status it rewrites, but I miss the upstream status. If I add 301 I keep the upstream status but I encounter cors.

Seems like a trivial task but from some reason I can’t find it, what am I doing wrong?

# example netlify.toml
[build]
  command = "npm run build:prod"
  functions = "netlify/functions"
  publish = "dist"

  ## Uncomment to use this redirect for Single Page Applications like create-react-app.
  ## Not needed for static site generators.
  [[redirects]]
    from = "/api/*"
    to = "https://dev.devcloud.zixi.com/:splat"
    status = 401
  [[redirects]]
    from = "/api/*"
    to = "https://dev.devcloud.zixi.com/:splat"
    force = true
    status = 200
  [[redirects]]
    from = "/*"
    to = "/index.html"
    status = 200


  ## (optional) Settings for Netlify Dev
  ## https://github.com/netlify/cli/blob/main/docs/netlify-dev.md#project-detection
  #[dev]
  #  command = "yarn start" # Command to start your dev server
  #  port = 3000 # Port that the dev server will be listening on
  #  publish = "dist" # Folder with the static content for _redirect file

  ## more info on configuring this file: https://docs.netlify.com/configure-builds/file-based-configuration/

If the upstream server sends the headers, the browsers will parse it. Netlify Rewrites do little to no filtering of headers received from upstream servers. So if the upstream server sends a 301, we pass it as it is to the browser and browser takes the necessary action. This cannot be contolled.

I’d advise creating a Function or an Edge Function that will follow all the redirects, fetch that data and return the final output.

You are right, the “bad rewrite” I’ve has was actually on the upstream server and it happened since I’ve configured a wrong path for the api.

Thanks.

Hi @adam.genshaft :wave:t6: thanks for letting us know what worked for you. We appreciate the feedback.