Rewrite Response Status Code


Is there a way with Caddy to rewrite the response status code on a condition? I hoped to achieve this with rewrite but it didn’t work out. Apparently it works like this with nginx:

error_page 403 =404 /404.html;

I want to rewrite 403 to 404 for a very specific use-case in bitwarden, which is described here

I think I cannot use the status directive since I don’t know which endpoint will trigger the 403 error. So yes, I want to rewrite all 403 to 404 for a specific host.

That’s what I tried:

rewrite {
    if {status} is 403
    to {status} 404


I don’t believe this is possible.

The status and rewrite directives operate earlier than proxy does in the middleware chain, so by the time Caddy has a response from upstream, it’s already too late to rewrite or issue a status manually.

This block of code dictates the order in which middleware operates on any given request.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.