# Condition with path\_reg and map\_dom with regexps

**URL:** <https://discourse.haproxy.org/t/condition-with-path-reg-and-map-dom-with-regexps/3297>\
**Category:** Help!\
**Created:** [December 4, 2018, 9:27pm UTC](https://discourse.haproxy.org/t/condition-with-path-reg-and-map-dom-with-regexps/3297 "2018-12-04T21:27:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![loxybjorn](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.haproxy.org/loxybjorn/32/705_2.png) [@loxybjorn](https://discourse.haproxy.org/u/loxybjorn)\
**Post date:** [December 4, 2018, 9:27pm UTC](https://discourse.haproxy.org/t/condition-with-path-reg-and-map-dom-with-regexps/3297/1 "2018-12-04T21:27:47Z")

</div>

Hi,

I’d like to match a sample (path) with a regular expression read from a map (with hdr(host) as a key). Is this possible somehow?

Example: Given a request with hdr(host) set to ‘[foo.com](http://foo.com)’ and path set to /bar I’d like to have a map file like this:  
[foo.com](http://foo.com) ^/bar/.\*

I posted basically the same question on [stackoverflow](https://stackoverflow.com/questions/53601885/haproxy-path-regexp-based-on-map-lookup) before I found this community.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![lukastribus](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@lukastribus](https://discourse.haproxy.org/u/lukastribus)\
**Post date:** [December 4, 2018, 9:54pm UTC](https://discourse.haproxy.org/t/condition-with-path-reg-and-map-dom-with-regexps/3297/2 "2018-12-04T21:54:56Z")

</div>

[base](https://cbonte.github.io/haproxy-dconv/1.8/configuration.html#7.3.6-base) contains a concatenation of hostname and path, that is what you want to match your map file against, it’s impossible to do so with 2 different variables (hostname AND path).

Then you can use string matches, substring matches or even regex - whatever you want, but against a _single_ string.

```
$ cat /etc/haproxy/base_to_backend.map
foo.com/bar/ foo
$

```

Exact string match:

```
use_backend bk-%[base,lower,map_str(/etc/haproxy/base_to_backend.map,bk_default)]

```

“beg” string match:

```
use_backend bk-%[base,lower,map_beg(/etc/haproxy/base_to_backend.map,bk_default)]

```

Or differently, you really need a regexp:

```
$ cat /etc/haproxy/base_to_backend.map
foo.com/(bar/|bob/|alice/) foo
$

use_backend bk-%[base,lower,map_reg(/etc/haproxy/base_to_backend.map,bk_default)]

```

Configs are untested, but you get the point.
