# HAproxy \> mapfile backendselection with directory

**URL:** <https://discourse.haproxy.org/t/haproxy-mapfile-backendselection-with-directory/4852>\
**Category:** Help!\
**Created:** [February 12, 2020, 10:27am UTC](https://discourse.haproxy.org/t/haproxy-mapfile-backendselection-with-directory/4852 "2020-02-12T10:27:49Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![makara1](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@makara1](https://discourse.haproxy.org/u/makara1)\
**Post date:** [February 12, 2020, 10:27am UTC](https://discourse.haproxy.org/t/haproxy-mapfile-backendselection-with-directory/4852/1 "2020-02-12T10:27:49Z")

</div>

Hey Guys, quite new here and also quite the beginner. I would like to match a domain and directory with my map file and i am wondering how to do this the best way.

As far as i can determine the backend selection currently functions with

`use_backend %[req.hdr(host),lower,map_dom(mapfile.txt,bk_defaultbackend)]`

with a mapfile.txt containing something like this:

`sub.domain.tld bk_subdomain`

when navigating to sub.domain.tld the properbackend will be selected. however i would like to be able to forward directories e.g

`sub.domain.tld/dir bk_otherbackend`

which does not work with map\_dom in the usebackend code. How would i go about this ? and how would i rewrite this line?

`use_backend %[req.hdr(host),lower,map_dom(mapfile.txt,bk_defaultbackend)]`

---

<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:** [March 5, 2020, 2:09pm UTC](https://discourse.haproxy.org/t/haproxy-mapfile-backendselection-with-directory/4852/2 "2020-03-05T14:09:18Z")

</div>

Use [base](https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#7.3.6-base) instead:

Something like (untested):

```
use_backend %[base,lower,map_beg(mapfile.txt,bk_defaultbackend)]

```

Correction: `map_beg` instead of `base_beg`

---

<div class="post-metadata">

**Author:** ![makara1](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@makara1](https://discourse.haproxy.org/u/makara1)\
**Post date:** [March 5, 2020, 4:10pm UTC](https://discourse.haproxy.org/t/haproxy-mapfile-backendselection-with-directory/4852/3 "2020-03-05T16:10:30Z")

</div>

I will give this a try and report back ! Thank you !

---

<div class="post-metadata">

**Author:** ![MarPiesceses](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@MarPiesceses](https://discourse.haproxy.org/u/MarPiesceses)\
**Post date:** [March 6, 2020, 3:27pm UTC](https://discourse.haproxy.org/t/haproxy-mapfile-backendselection-with-directory/4852/4 "2020-03-06T15:27:08Z")

</div>

some updates? really interested in how it worked out. thanks

---

<div class="post-metadata">

**Author:** ![makara1](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@makara1](https://discourse.haproxy.org/u/makara1)\
**Post date:** [March 9, 2020, 8:37am UTC](https://discourse.haproxy.org/t/haproxy-mapfile-backendselection-with-directory/4852/5 "2020-03-09T08:37:58Z")

</div>

> [@lukastribus](#):
>
> use\_backend %[base,lower,map\_beg(mapfile.txt,bk\_defaultbackend)]

So when i change my backend selection in this way, it doesn’t break anything which is good. Some of my redirects work half way through some don’t. not really sure tbh. I need some more time testing it.

In order to test this better i have to set up two static webservers. i’ll report back

---

<div class="post-metadata">

**Author:** ![MarPiesceses](https://avatars.discourse-cdn.com/v4/letter/m/f17d59/32.png) [@MarPiesceses](https://discourse.haproxy.org/u/MarPiesceses)\
**Post date:** [March 9, 2020, 4:40pm UTC](https://discourse.haproxy.org/t/haproxy-mapfile-backendselection-with-directory/4852/6 "2020-03-09T16:40:51Z")

</div>

> [@lukastribus](#):
>
> Use [soups](https://delicerecipes.com/category/recipes/soups/) instead:
> 
> Something like (untested):

doesn’t work for me. are you still here? want to ask you something if you don’t mind.

---

<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:** [March 9, 2020, 4:54pm UTC](https://discourse.haproxy.org/t/haproxy-mapfile-backendselection-with-directory/4852/7 "2020-03-09T16:54:06Z")

</div>

It works for me, I actually tested it a few days ago.

Please stop asking if you can ask, and just ask your question. If it is related to this thread, then you ask here, otherwise you open a new thread. But asking if you can ask a question actually is a waste of both our time. Thank you.

---

<div class="post-metadata">

**Author:** ![makara1](https://avatars.discourse-cdn.com/v4/letter/m/439d5e/32.png) [@makara1](https://discourse.haproxy.org/u/makara1)\
**Post date:** [March 9, 2020, 5:04pm UTC](https://discourse.haproxy.org/t/haproxy-mapfile-backendselection-with-directory/4852/8 "2020-03-09T17:04:30Z")

</div>

so it works for you that if you have in your map file

```
test.tld/site1 backend_siteone
test.tld/site2 backend_sitetwo  

```

it selects the proper backend when you navigate to either?

---

<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:** [March 9, 2020, 5:11pm UTC](https://discourse.haproxy.org/t/haproxy-mapfile-backendselection-with-directory/4852/9 "2020-03-09T17:11:31Z")

</div>

My testcase was slightly different, but yes, that’s how it is supposed to work.
