A Traefik middleware plugin to redirect to another URL on specific HTTP statuses.
Similar to the built-in Errors
middleware, but this generates a HTTP 302 redirect, instead of an internal proxy action.
It was created to make ForwardAuth
easier to use.
Example configuration with ForwardAuth
:
# Static configurationexperimental:plugins:redirectErrors:moduleName: github.com/indivisible/redirecterrorsversion: v0.1.0
# Dynamic configurationhttp:routers:secured-router:rule: host(`secured.localhost`)service: service-securedmiddlewares:- auth-redirectauth-router:rule: host(`auth.localhost`)service: service-authmiddlewares:- my-pluginservices:service-secured:loadBalancer:servers:- url: http://localhost:5001/service-auth:loadBalancer:servers:- url: http://localhost:5002/middlewares:auth-redirect-error:plugin:redirectErrors:status:- "401"target: "http://auth.localhost/oauth2/sign_in?rd={url}"outputStatus: 302auth-check:forwardAuth:address: "http://localhost:5002/oauth2/auth"trustForwardHeader: trueauth-redirect:chain:- auth-redirect-error- auth-check
status
: list of statuses / status ranges (eg 401-403
). See the Error middleware's description for details.target
: redirect target URL. {status}
will be replaced with the original HTTP status code, and {url}
will be replaced with the url-safe version of the original, full URL.outputStatus
: HTTP code for the redirect. Default is 302.