ReplacePathRegex docker provider not working

I have the following labels on one of my docker-compose services. I'm trying to rewrite a url like to With this setup, when I curl a path like, it seems like the middleware is bypassed completely.

I can see the middleware is attached to the router, so I figured i must be using the regex values incorrectly? Thanks!

      - "traefik.http.routers.internal-api.rule=Host(``) && Path(`/api/v5`)"
      - "traefik.http.middlewares.internal-api-replace-path.replacepathregex.regex=^/api/v5/(.*)"
      - "traefik.http.middlewares.internal-api-replace-path.replacepathregex.replacement=/$$1"
      - "traefik.http.routers.internal-api.middlewares=internal-api-replace-path@docker"


This is working here :

  - "traefik.http.routers.internal-api.rule=Host(``) && Path(`/api/v5`)"
  - "traefik.http.routers.internal-api.middlewares=internal-api-replace-path@docker"
  - "traefik.http.middlewares.internal-api.middlewares.replacepathregex.regex=^/app/v5/(.*)"
  - "traefik.http.middlewares.internal-api.middlewares.replacepathregex.replacement=/$1"

The problem i think, is the double '$$'

That's strange, I was sure that docker-compose uses $ for variable substitution, and you need to escape it (e.g. $$) to make it interpret it literally.

You said it : docker compose uses $ and need escape for variable substitution.

Docker write this line as a labels of the container, this line is not interpreted by docker but by traefik

Was not talking about docker but about docker-compose. If you specify the label in the docker-compose you will have to double the dollar sign to avoid it being interpreted as a variable. In oder for this line to be interpreted by traefik it first needs to get to traefik. This is happening by docker-compose executable reading the yaml, and then executing docker commands, that decorate the container with the label. This all happens before traefik had a chance to read them. Now when the label is set and ready for traefik to be read, the yaml parsing is long finished by then and variables with $ are already substituted.

I'm having a similar issue. I detailed my user case here.

      #### core configs
      - "traefik.enable=true"
      # - "traefik.http.routers.caddy.service=nginx" # swarm
      - "traefik.http.routers.nginx.rule=Host(``) && PathPrefix(`/nginx`)"
      - ""
      #### set TLS (https)
      - "traefik.http.routers.nginx.entrypoints=websecure"
      - "traefik.http.routers.nginx.tls=true"
      - "traefik.http.routers.nginx.tls.certresolver=leresolver"
      #### use these middlewares (rules like our-auth,our-retry,our-ratelimit are defined within traefik's labels)
      - "traefik.http.routers.nginx.middlewares=our-retry,our-ratelimit,our-header,nginx-strip,nginx-pathregex"
        #___ specific middleware rule for this service
      - "traefik.http.middlewares.nginx-strip.stripprefix.prefixes=/nginx"
        #___ add missing trailing slash / not working :-/
      - "traefik.http.middlewares.nginx-pathregex.replacepathregex.regex=^/nginx/(.*)"
      - "traefik.http.middlewares.nginx-pathregex.replacepathregex.replacement=/nginx/$$1"

When using a single $ docker is giving me this error:

ERROR: Invalid interpolation format for "labels" option in service "nginx": "traefik.http.middlewares.nginx-pathregex.replacepathregex.replacement=/nginx/$1"

@kwngo, have you resolved your issue?

Here is the solution to add a missing trailing slash.