title: How to rewrite domain.com to www.domain.com with HAProxy?
body: <p>We have 1 loadbalancer with 3 members behind it:</p>
  
  <p>main balancer: www.website.com
  members: web1.website.com, web2.website.com and web3.website.com</p>
  
  <p>Currently we are using nginx on the loadbalancer, but we want to replace it with HAProxy. </p>
  
  <p>Nginx rewrites the domain without www (domain.com) to www.domain.com with the following line:</p>
  
  <pre><code>server {
      server_name domain.com;
      listen 1.2.3.4:80;
  
      rewrite ^(.*) http://www.domain.com$1 permanent;
  }
  </code></pre>
  
  <p>How can I manage this with HAproxy?</p>
  
  <p>My haproxy config:</p>
  
  <pre><code>frontend http 1.2.3.4:80
  
      default_backend www_cluster
      acl is_www hdr_end(host) -i www.domain.com
      use_backend www_cluster if is_www
  
  
  backend www_cluster
  
      balance roundrobin
      cookie SERVERID insert nocache indirect
  
      option httpchk HEAD / HTTP/1.0
      option httpclose
      option forwardfor
  
      server web1 1.2.3.5:82 cookie WEB1 check
      server web2 1.2.3.6:82 cookie WEB2 check
      server web3 1.2.3.7:82 cookie WEB3 check
  </code></pre>
  
  <p>TIA!</p>