HAProxy Redirect domain to another domain

From Brian Nelson Ramblings
Jump to: navigation, search

HAProxy Redirect domain to another domain

From time to time, you may find yourself wanting to redirect a domain to a folder on another domain

You will want to edit the haproxy.cfg file

vim /etc/haproxy/haproxy.cfg

Then add something like the following to the frontend in haproxy.

acl demoredirect hdr_dom(host) -i demofolder.com
acl demoredirect hdr_dom(host) -i www.demofolder.com
http-request redirect location https://briansnelson.com/demofolder/ code 301 if demoredirect

Save and check your configuration

service haproxy check

You are looking for

Configuration file is valid

Next restart or start the server to start redirecting from one domain to another

service haproxy restart/start