Redirect Path to the container with first path

Hi everyone,

I am trying to setup a traefik container that redirects all request to localhost:80 automatically to the good container like this :

What did I expect to see?

  1. When I go to localhost/<container-name>/hello
  2. Redirect to the container named , so <container-name>/hello

What did I see instead?

  1. When I go to localhost/<container-name>/hello
  2. I am redirected to the <container-name>/<container-name>/hello
    The problem is that the path /<container-name>/hello is keeped so I want to remove /<container-name>

My traefik configuration

## traefik.yml
accessLog: {}
# Docker configuration backend
    defaultRule: "PathPrefix(`/{{ .Name }}`)"

# API and dashboard configuration
  debug: true
  insecure: true

Someone have an idea, how to do that ?

Hi @bruno-motacardoso, you need to enable (and configure) a middleware named "Strip Prefix" for each router. You can find here the documentation of the middleware:, and here an example of this use case: .

Hi @dduportal , thanks for your answer. Can I configure this middleware for each router automatically?
Does it exist a defaultMiddleware in docker provider like defaultRule ?
Like this, the traefik configuration be completely independent to docker containers.

Hi @bruno-motacardoso , it is not possible as far as I know, since the goal of Traefik is to get its configuration from the backends metadatas (container's labels, Kubernetes manifests, etc.).

Only the defaultRule can be defined in this case.

Ok thanks for your clear answer

1 Like