What happens when traefik redirectregex middleware's regex does not match?

Will the middleware be ignored?

If the middleware regex matches, it will redirect, otherwise the processing will continue.

From simple Traefik example:

services:
  whoami:
    image: traefik/whoami:v1.10
    networks:
      - proxy
    labels:
      - traefik.enable=true
      - traefik.http.routers.mywhoami.rule=Host(`whoami.example.com`) || Host(`www.whoami.example.com`)
      - traefik.http.routers.mywhoami.middlewares=mywwwredirect
      - traefik.http.middlewares.mywwwredirect.redirectregex.regex=^https://www\.(.*)
      - traefik.http.middlewares.mywwwredirect.redirectregex.replacement=https://$${1}
      - traefik.http.services.mywhoami.loadbalancer.server.port=80

A single router will match "www" and non-www. "www" will be redirected, only non-www will continue to target service.

1 Like

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