title: HAProxy and URL Rewriting Configuration
body: <p>I would like to ask how HAProxy can help in routing requests depending on parts of the URL.</p>
  
  <p>To give you an overview of my setup, I have the HAProxy machine and the two backends:</p>
  
  <ul>
  <li>IIS website (main site)</li>
  <li>Wordpress blog on NGINX (a subsite)</li>
  </ul>
  
  <hr>
  
  <p><strong>The use-case:</strong> </p>
  
  <p>I'm expecting to route requests depending on the URL:</p>
  
  <ul>
  <li>www.website.com/lang/index.aspx -> main site</li>
  <li>www.website.com/lang/blog/articlexx -> blog subsite</li>
  </ul>
  
  <p>The blog access URL is "<em>/server/blog/lang/articlexx</em>" so I have to rewrite the original client request to that format--which is basically switching "blog" and "lang".</p>
  
  <p>From how I understood the configuration documentation and some posts on the net, I could use reqrep/reqirep to change the request HTTP headers before it gets passed to a backend. And if that's right, then this configuration should work:</p>
  
  <pre><code>frontend vFrontLiner
      bind            x.x.x.x:x
      mode            http
      option          httpclose
      default_backend iis_website
  
      # the switch: x/lang/blog -? x/blog/lang
      reqirep ^/(.*)/(blog)/(.*) /if\2/\1/\3
  
      acl blog path_beg -i /lang/blog/
  
      use_backend blog_website if blog
  
  
  backend blog_website
      mode    http
      option  httpclose
      cookie  xxblogxx insert indirect nocache
      server  BLOG1 x.x.x.x:80 cookie s1 check inter 5s rise 2 fall 3
      server  BLOG2 x.x.x.x:80 cookie s2 check inter 5s rise 2 fall 3 backup
  </code></pre>
  
  <p><strong>The problem:</strong> The requests being received by the blog_website backend is still the original URL "x/lang/blog".</p>
  
  <p>I might have missed something on the regex part but my main concern is whether my understanding correct or not to use the reqirep in the first place. I would appreciate any help.</p>
  
  <p>Thanks very much.</p>