title: haproxy absolute redirect for an entire domain
body: <p>I have been googling for hours with no luck for something that has got to be simple.</p>
  
  <p>I am using haproxy 1.7 and am attempting a 301 redirect for all traffic from one domain to another "landing page" with partial success. I can get a basic redirect to work, however if someone uses a bookmarked link for example, they will get a 404, since the URL does not exist on the new domain.</p>
  
  <p>domain1.com/foo or domain1.com/bar/baz/whatever all need to get redirected without exception to domain2.com/landing  I cannot find an acl in any examples on how to do this.  I know it has got to be some kind of rewrite rule before the reidrect, but I cannot get one to work.</p>
  
  <p>Here is some of the settings I have tried:</p>
  
  <pre><code>#        reqrep ^([^\ ]*)\ /(.*)  \1\ /\2 if domain1_host
  #        redirect location https://domain2.com/landing  code 301  prefix /landing drop-query if domain1_host
  #        http-request replace-header X-REWRITE ^/.*?$ /\1 if domain1_host
  #        reqrep ^([^\ ]*\ /)(.*) \1landing\2 if domain1_host
  #        reqrep ^([^\ ]*\ /)[/]?(.*)     \1\2 if domain1_host
  #        reqrep ^([^\ ]*)\ /(.*) \1\ /\2 if domain1_host
  #        redirect prefix https://domain2.com/landing code 301  if domain1_host
  redirect scheme https://domain2.com/landing code 301  if domain1_host
  </code></pre>
  
  <p>If anyone has some suggestions on what I have missed, I would really appreciate some direction. </p>