# Redirect based on hostname

**URL:** <https://discourse.haproxy.org/t/redirect-based-on-hostname/6747>\
**Category:** Help!\
**Created:** [July 20, 2021, 1:29pm UTC](https://discourse.haproxy.org/t/redirect-based-on-hostname/6747 "2021-07-20T13:29:58Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hexil](https://avatars.discourse-cdn.com/v4/letter/h/5e9695/32.png) [@hexil](https://discourse.haproxy.org/u/hexil)\
**Post date:** [July 20, 2021, 1:29pm UTC](https://discourse.haproxy.org/t/redirect-based-on-hostname/6747/1 "2021-07-20T13:29:58Z")

</div>

Hello there,

I’m having trouble setting up HAProxy for my application.

I need to redirect to a path based on the hostname.

For example the server where HAProxy is listening respond to two hostnames: “fooBAR.app” and “FOObar.app”.

Now when I send a request to “[http://foo.app/](http://foo.app/)” I would like it to be sent to 1.2.3.4:8080/fooBAR-application/, same for “[http://FOO.app/](http://FOO.app/)” that should go to 1.2.3.4:8080/FOObar-application/.

This is my cfg file:

```auto
#---------------------------------------------------------------------
# globals
#--------------------------------------------------------------------
global
    log 127.0.0.1 local0
    user haproxy
    group haproxy
    daemon

#---------------------------------------------------------------------
# common defaults
#----------------------------------------------------------------------
defaults
    log global
    option httplog
    mode http
    retries 3
    timeout http-request 10s
    timeout queue 1m
    timeout connect 10s
    timeout client 1m
    timeout server 1m
    timeout http-keep-alive 10s
    timeout check 10s
    maxconn 3000

#---------------------------------------------------------------------
# main frontend
#---------------------------------------------------------------------
frontend main_fe
    bind *:80

    acl fooBAR hdr(host) -i fooBAR.app
    acl FOObar hdr(host) -i FOObar.app

    http-request set-path /fooBAR-application/ if fooBAR
    http-request set-path /FOObar-application/ if	FOObar

    use_backend fooBAR_be if fooBAR
    use_backend FOObar_be if FOObar

    default_backend fooBAR_be

#---------------------------------------------------------------------
# main backend
#---------------------------------------------------------------------
backend fooBAR_be
    balance roundrobin
    server fooBAR1 172.21.80.13:8080 check

backend FOObar_be
    balance roundrobin
    server FOObar1 172.21.80.13:8080 check

```

Many thanks.
