How to redirect URL with HAProxy

本秂侑毒 提交于 2019-12-12 08:23:20

问题


I need 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 have tried with redirect prefix but don't work, any idea?


回答1:


Change order of the 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 of

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 }


来源:https://stackoverflow.com/questions/28530087/how-to-redirect-url-with-haproxy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!