Use header in middleware as a variable

Simple question. I want to use ReplacePathRegex middleware but i want to inject a content of one custom header into the path where i want rewrite to point to.

for example:

  • "traefik.http.middlewares.test-replacepathregex.replacepathregex.regex=^/foo/(.*)"
  • "traefik.http.middlewares.test-replacepathregex.replacepathregex.replacement=/bar/{REQUEST_HEADER_BLA}/$1"

Is this possible to do in Traefik v2?

1 Like

I am using Traefik v2.9 and I do have the same request.

After looking at the documentation, forum and GitHub issues.. It looks like it is still not possible to achieve such a redirection.

Is it possible to know why?

Maybe it’s a rare use case. You could (or pay a dev to) create a Traefik plugin with this functionality, then submit it to the open source collection (link).

According to this GitHub issue, it looks like a plugin has already been developed.

Is there a similar plugin already published to the plugin catalog?

Not sure. Have you checked one of the header plugins (link)? Maybe that is the right place to add your feature? It seems to be maintained.

This plugin does not fit the need of this thread.

Referring to the example above, the goal is to apply a replacement using replacepathregex depending on the header variable (browser language, format, ...).

Is it possible to know why a plugin is needed? and not handled by Traefik itself?

It’s like 3 people over 3 years asked for such a feature. You are asking in the community forum, so you are probably not a paying customer. So there seems to be little business value to it.

The Traefik developers don’t like to bloat their code, especially not with features <1% of us users will use. So I think it’s great to have a plugin system for very special requirements.

Based on various forum discussion threads and GitHub issues from the past years, I'd estimate that the number of affected users is more than 1%. This might be a reason why people continue to opt for other reverse proxies.

Anyway, thank you for the clarification. I'll check if this plugin is feasible.