I need to have 301 redirect from example.com to www.example.com and from www.example.com/fr to www.example.com/fr/eshop
My haproxy.cfg:
globallog stdout format raw local0defaultslog globalmode httpoption dontlognulloption http-ignore-probeslog-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 forwardfortimeout connect 30stimeout client 30stimeout server 30sfrontend httpbind *:8080# redirect to wwwhttp-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 /deacl path_fr path_beg /fracl path_fr_eshop path_beg /fr/eshophttp-request replace-path /fr(.*) /fr/eshop\1 if path_fr !path_fr_eshopuse_backend de if path_deuse_backend fr if path_frdefault_backend debackend dehttp-request set-header Host www.example.comserver de-gw 91.X.X.X:443 check ssl verify nonebackend frhttp-request set-header Host www.example.comserver fr-gw 10.X.X.X:80
With this config redirect from non-www to www works fine
This also works fine: www.example.com/fr is getting redirected to www.example.com/fr/eshop
but www.example.com/fr/ is getting redirected to www.example.comfr/eshop/fr
I tried with following below replace-path:
http-request replace-path ^/fr(/|$)(.*) /fr/eshop\1\2 if path_fr !path_fr_eshop
but it did not help behavior is the same, /fr/ is getting redirected to /fr/eshop/fr
Best Answer
Evetything works OK with following replace-path:
http-request replace-path /(.*) /fr/eshop if path_fr !path_fr_eshop