How to redirect a URL using HAProxy

I need to redirect www.foo.com and foo.com to www.bar.com in haproxy, this is my configuration:

frontend http-in bind *:80 acl bar.com hdr(host) -i www.bar.com ... use_backend bar.com_cluster if bar.com ... redirect prefix http://foo.com code 301 if { hdr(host) -i www.bar.com } redirect prefix http://www.foo.com code 301 if { hdr(host) -i www.bar.com } ... backend bar.com_cluster balance roundrobin option httpclose option forwardfor server bar 10.0.0.1:80 check 

I tried with redirect prefix but not working, any idea?

+5
source share
1 answer

Reorder hostname:

 redirect prefix http://www.bar.com code 301 if { hdr(host) -i foo.com } redirect prefix http://www.bar.com code 301 if { hdr(host) -i www.foo.com } 

instead

 redirect prefix http://foo.com code 301 if { hdr(host) -i www.bar.com } redirect prefix http://www.foo.com code 301 if { hdr(host) -i www.bar.com } 
+10
source

Source: https://habr.com/ru/post/1213426/


All Articles