title: HAProxy path regexp based on map lookup
body: <p>I'm using HAProxy 1.8.14 on a server running Debian stretch.</p>
  
  <p>I want to route requests to different backends for a certain set of domains but only for some specific paths. Since there's quite a few domains and varying paths allowed I think a solution using maps would be nice.</p>
  
  <p>I've tried to use a map to lookup a backend based on hdr(host) with the condition that the path should match with a regular expression mapped to hdr(host). I've tried the following but I can't get it to work:</p>
  
  <pre><code>use_backend bk-%[hdr(host),lower,map_dom(/etc/haproxy/host_to_backend.map,bk_default)] if { path_reg %[hdr(host),lower,map_dom(/etc/haproxy/domain_path_whitelist.map)] }
  </code></pre>
  
  <p>Example of host_to_backend.map:</p>
  
  <pre><code>a.foo.org a
  b.foo.org b
  c.foo.org c
  </code></pre>
  
  <p>Example of domain_path_whitelist.map (regexps not tested):</p>
  
  <pre><code>a.foo.org ^/(yada|info)/.*$
  b.foo.org ^.*$
  c.foo.org ^/bar/.*$
  </code></pre>
  
  <p>To avoid the regexp complexities I've also tried a 'beg' alternative:</p>
  
  <pre><code>use_backend bk-%[hdr(host),lower,map_dom(/etc/haproxy/host_to_backend.map,bk_default)] if { path_beg %[hdr(host),lower,map_dom(/etc/haproxy/domain_path_whitelist.map)] }
  </code></pre>
  
  <p>...but no luck.</p>
  
  <p>Is it possible to solve my specific problem using maps? If not, can you suggest an alternative solution?</p>