如何将PathPrefixStrip与Redirect结合使用:正则表达式?

时间:2018-04-16 21:31:53

标签: traefik

我的配置如下:

前端

traefik.frontend.rule=Host:my.domain;PathPrefixStrip:/mypath/

traefik param

--entrypoints="Name:http Address::80 Redirect.EntryPoint:https Redirect.Regex:http://my.domain/(.*)$ Redirect.Replacement:https://my.domain/$1 Redirect.Permanent:true"

我的目标是将给定路径上的HTTP请求重定向到其HTTPS端点。但是,路径前缀删除似乎发生在之前" main" redirect.regex / replacement逻辑,打破了一些请求。例如:

http://my.domain/mypath/v1/foo

将成为:

https://my.domain/v1/foo

虽然我期望它是:

https://my.domain/mypath/v1/foo

无论如何要解决这个问题?

1 个答案:

答案 0 :(得分:0)

  

请注意,如果为重定向定义了regex,则不必在重定向结构中设置replacemententrypoint(在这种情况下不会使用它们)。

https://docs.traefik.io/v1.5/configuration/entrypoints/#redirect-http-to-https

另请注意Redirect.Permanent:true进入1.6

尝试类似的东西:

--entrypoints="Name:http Address::80 Redirect.Regex:http://my.domain/(.*)$ Redirect.Replacement:https://my.domain/mypath/$1 Redirect.Permanent:true"