Similar to HAProxy reqrep remove URI on backend request.
The following concerns apply for us.
We have applications which were running with different context roots off one domain. However not all clients of the urls were changed.
I would like to redirect with a 301 redirect in haproxy if a request matches a legacy path.
Take for example http://example.com/abc
and http://example.com/def
...
frontend https
bind *:{{ proxy_port }} ssl crt /etc/haproxy/bundle_dh.pem ciphers ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4 no-sslv3
http-request set-header X-Forwarded-Proto https if { ssl_fc }
http-request set-header X-Forwarded-Port %[dst_port]
acl has_legacy_abc path_beg /abc
acl has_legacy_def path_beg /def
redirect location 301 https://abcdomain.com/{PATH_WITHOUT_ABC} if { has_legacy_abc }
redirect location 301 https://defdomain.com/{PATH_WITHOUT_ABC} if { has_legacy_def }
use backend abc_backend if { hdr(Host) -i abcdomain.com }
use backend def_backend if { hdr(Host) -i defdomain.com }
...
The problem is how to retain the path in the redirect. I can do an absolute redirect.
Looked and reqrep
but that seems to be for changing a request before passing to a backend. I want to tell all visitors they should go to the new domain.