Search code examples
traefik

Traefik - redirect not work with PathPrefixStrip without slash


i need redirect a specific /path, i write this compose:

web1:
    image: httpd
    labels:
      - "traefik.backend=httpd"
      - "traefik.frontend.rule=Host:www.example.com"
      - "traefik.port=80"
web2:
    image: nginx
    labels:
      - "traefik.backend=nginx"
      - "traefik.frontend.rule=Host:www.foobar.com"
      - "traefik.port=80"   
app:
    image: custom/image
    labels:
      - "traefik.backend=app"
      - "traefik.frontend.rule=Host:www.example.com,www.foobar.com; PathPrefixStrip:/app"
      - "traefik.port=80"

When i go to http://www.example.com/app and http://www.foobar.com/app i need go into container app, but work only if i insert a / at the end of URL:

http://www.example.com/app not work

http://www.foobar.com/app not work

http://www.example.com/app/ work

http://www.foobar.com/app/ work

I have already a version of this app that work with an apache alias, I suppose it's not a problem of the app

Thanks


Solution

  • I've found solution here: https://github.com/containous/traefik/issues/563#issuecomment-421360934

    labels:
      - "traefik.frontend.redirect.regex=^(.*)/path$"
      - "traefik.frontend.redirect.replacement=$1/path/"
      - "traefik.frontend.rule=PathPrefix:/path;ReplacePathRegex: ^/path/(.*) /$1"