HTTP router with host and PathRegexp

Hello All,
I'me trying to create an http router that match Host and PathRegexp.
Our goal is to route images requests to a container and all the other traffic to another container using docker swarm an labels.
I tried to add the following label to the "images" container:

  • "traefik.http.routers.wwwexamplecom.rule=(Host( && PathRegexp(\\.(jpeg|jpg|png)$$))"

and the following label to the "all the other traffic" container (negating the PathRegexp):

  • "traefik.http.routers.wwwexamplecom.rule=(Host( && !PathRegexp(\\.(jpeg|jpg|png)$$))"

I have the error: "error while parsing rule (Host( && PathRegexp(\.(jpeg|jpg|png)$)): unsupported function: PathRegexp"

Could you help me to fix the rule or give me other suggestions?
Thank you very much in advance

Seems you need to use Path instead of PathRegex, see docs. I think there was a change with v3, but I don’t remember if they added or removed it. :slight_smile:

You don’t need the negated PathRegex, you can remove it. Then the rule with PathRegex is longer, has higher priority, and Traefik will automatically fall back to the second one without if the first one is not matching.

Thankyou bluepuma77,
after a couple of tests I found the solution using path and with two hosts following your suggestion.

"traefik.http.routers.wwwexamplecom.rule=((Host( || Host( && Path(/{path:(.*.(jpeg|jpg|png))}))"

Thanks Again