HAProxy 2.5 http-request replace-path 无法正常工作

HAProxy 2.5 http-request replace-path not working correctly

我需要从 example.com 到 www.example.com and from www.example.com/fr to www.example.com/fr/eshop

的 301 重定向

我的haproxy.cfg:

global
    log stdout format raw local0

defaults
    log         global
    mode        http
    option      dontlognull
    option      http-ignore-probes
    log-format  "%ci:%cp [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"
    option      forwardfor
    timeout     connect 30s
    timeout     client 30s
    timeout     server 30s

frontend http
    bind *:8080

    # redirect to www
    http-request redirect code 301 location https://www.example.com%[capture.req.uri] if { hdr(host) -i example.com }

    ### ACLs AND REDIRECTS ###
    acl path_de path_beg /de
    acl path_fr path_beg /fr
    acl path_fr_eshop path_beg /fr/eshop
    http-request replace-path /fr(.*) /fr/eshop if path_fr !path_fr_eshop
    use_backend de if path_de
    use_backend fr if path_fr
    default_backend de

backend de
    http-request set-header Host www.example.com
    server de-gw 91.X.X.X:443 check ssl verify none

backend fr
    http-request set-header Host www.example.com
    server fr-gw 10.X.X.X:80

使用此配置从非 www 重定向到 www 工作正常

这也很好用:www.example.com/fr is getting redirected to www.example.com/fr/eshop

但是www.example.com/fr/ is getting redirected to www.example.comfr/eshop/fr

我尝试使用以下替换路径:

http-request replace-path ^/fr(/|$)(.*) /fr/eshop if path_fr !path_fr_eshop

但它没有帮助行为是一样的,/fr/ 被重定向到 /fr/eshop/fr

使用以下替换路径一切正常:

http-request replace-path /(.*) /fr/eshop if path_fr !path_fr_eshop