Difference between revisions of "HAProxy Redirect domain to another domain"

From Brian Nelson Ramblings
Jump to: navigation, search
(Created page with "==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 th...")
 
(Next restart or start the server to start blocking by ip address)
 
Line 21: Line 21:
 
  Configuration file is valid
 
  Configuration file is valid
  
===Next restart or start the server to start blocking by ip address===
+
===Next restart or start the server to start redirecting from one domain to another===
  
 
  service haproxy restart/start
 
  service haproxy restart/start

Latest revision as of 03:57, 25 November 2020

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