Redirect based on hostname

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/” I would like it to be sent to 1.2.3.4:8080/fooBAR-application/, same for “http://FOO.app/” that should go to 1.2.3.4:8080/FOObar-application/.

This is my cfg file:

#---------------------------------------------------------------------
# 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.