RedirectRegex middleware is not doing what I expect

Hello,

I'm trying to set up RedirectRegex to take example.org/c/foobar and turn it into sub.example.org/foobar, however instead it it turning it into sub.example.org/c/foobar and I have no idea how to fix that.

labels:
  - "traefik.http.routers.application.rule=Host(`sub.example.org`)"
  - "traefik.http.routers.application.entrypoints=web,webSecure"
  - "traefik.http.routers.application.service=application"
  - "traefik.http.services.application.loadbalancer.server.port=80"
  - "traefik.http.routers.redirect.rule=Host(`example.org`)&&PathPrefix(`/c/`)"
  - "traefik.http.routers.redirect.entrypoints=web,webSecure"
  - "traefik.http.routers.redirect.middlewares=redirect@docker"
  - "traefik.http.middlewares.redirect.redirectregex.regex=^http://localhost/(.*)"
  - "traefik.http.middlewares.redirect.redirectregex.replacement=https://sub.example.org/$${1}"

I've seen that PathPrefix "forwards the path as is" and have tried ^http://localhost/c/(.*) as the regex but saw no change. I've also tried hardcoding https://sub.example.org/foobar as the replacement but it still directed to https://sub.example.org/c/foobar.

I have no idea what I am doing to make this not work as expected, any help pointing me in the right direction would be appreciated. Thanks

I ended up figuring out a solution.

I added a StripPrefix middleware after the RedirectRegex and that seemed to do the trick.

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