Good afternoon,

I've got some questions about how to use 'redirect' or 'http-request
redirect' to provide some functionality.

A little bit of background.

I've got a COTS application that is accessed via given domain name,
let's say http://blah.foo.com.

Given that the COTS only supports a single language per instance, there
are various instances installed on different ports in the back end,
which use the first level of the path to specify the language, such that
a client would go to http://blah.foo.com/fr for a French version of the
site, and http://blah.foo.com/en for an English version. This is what's
currently in place and the site works as expected. In the config below,
there are a few other lines to allow for a shared image directory and
splash page which allows for the selection of a language if one isn't
already specified.

We're to be upgrading the version of the COTS and at the same time,
we're going  to change the domain name to 'cots.foo.com', but we want to
allow any legacy links stored on PCs, in bookmarks or in emails to still
function.

The new version natively support multiple languages, such that the '/en'
and '/fr' path components are no longer needed, and can simply be
replaced with a single base URL, '/app'.

I'd like to redirect the users to the new URL, so that no matter what
they clicked, when they look in the address bar, they see the new URL.

To summarize, I'd like the following:
http://blah.foo.com/en/folder/path/918374 or
http://blah.foo.com/fr/folder/path/918374
http://blah.foo.com/en/file?function=index or
http://blah.foo.com/fr/file?function=index 

To be redirected to
http://cots.foo.com/app/folder/path/918374 
http://cots.foo.com/app/file?function=index 

My first thought was to use the 'redirect' directive, but that wouldn't
allow for the change in path.

I then saw that I can possibly use 'http-request redirect', but it's
really not clear how I would extract the various components of the path
(anything after the second slash) for use in the newly built URL. The
example at the very bottom of the docs section for 'redirect' is very
interesting to me:
http-request redirect code 301 location www.%[hdr(host)]%[req.uri]
unless { hdr_beg(host) -i www }

>From what I can gather from that line, I might be able to do something
like the following to change the domain name, but even then there's no
way to strip out the path components I need:
http-request redirect code 301 location
http://cots.foo.com/%[capture.req.uri] if { hdr(host) -i blah.foo.com }

I could transparently accept the old URLs and simply 'reqrep' them to
the backend, but I'd really rather not since that would keep the old
URL's fully active instead of redirecting them as I'd like to do.

If I'm way off in trying to do this on the load-balancer, then let me
know so I can try and find a solution elsewhere.

Thank you.

For reference here's a copy of my current config file.
# ---- Global Config ----
#Setup the global config
global

  crt-base /path/to/certs
  daemon
  group nobody
  log /dev/log local0
  maxconn 100000
  nbproc 1
  user haproxy
  spread-checks 5
  stats socket /path/to/socket/haproxy.sock mode 600 level admin
  stats timeout 5m

  tune.ssl.default-dh-param 2048

# ---- Defaults ----
#Set some defaults
defaults
  balance roundrobin
  compression algo gzip
  compression type application/javascript application/json text/css
text/html text/plain text/xml
  maxconn 50000
  mode http
  option abortonclose
  option contstats
  option httplog
  option redispatch
  timeout connect 15s
  timeout client 30s
  timeout server 30s
  default-server weight 100 inter 30s fastinter 5s downinter 1m


#
------------------------------------------------------------------------
---
#                               Listen
#
------------------------------------------------------------------------
---

  # ---- STATS ----
  listen LI-Stats
    bind 12.23.56.78:8888 ssl crt /path/to/certs/cert.pem
    mode http
    log global
    stats enable
    stats refresh 60
    stats show-legends
    stats show-node
    stats auth un:pw
    stats admin if TRUE


#
------------------------------------------------------------------------
---
#                               Frontends
#
------------------------------------------------------------------------
---

  # ---- HTTPS - Shared -----
  # Frontend to support shared HTTPS connections
  frontend LI-HTTPS-Shared
    # Options
    log /dev/log local1
    mode http
    option httplog
    option forwardfor

    # Bind to the port and use the cert specified
    bind 12.34.56.11:443 ssl crt /path/to/certs/cert-https.pem
    bind 12.34.56.11:80

    # Options
    maxconn 50000

    # -- ACLs --
     acl url-path_blah_splash       path /
     acl url-path_blah_splash       path_beg -i /images /css
     acl url-path_blah_en           path_beg -i /en
     acl url-path_blah_fr           path_beg -i /fr
     acl url-path_blah_img          path_beg -i /img
     acl hdr-host_blah              hdr(host) -i blah.foo.com

    # -- Redirects --
     # - Global SSL Redirector -
     redirect scheme https                       if !{ ssl_fc }

    # -- Backend Selection --
     use_backend BE-Blah-En         if hdr-host_blah url-path_blah_en
     use_backend BE-Blah-Fr         if hdr-host_blah url-path_blah_fr
     use_backend BE-Blah-Splash     if hdr-host_blah
url-path_blah_splash
     use_backend BE-Blah-Img        if hdr-host_blah url-path_blah_img


#
------------------------------------------------------------------------
---
#                                Backends
#
------------------------------------------------------------------------
---

  backend BE-Blah-Splash
    # Define some options
    balance leastconn
    log /dev/log local3
    mode http
    option httplog
    option httpchk /img/login.gif
    option httpclose

    #Active Servers
    default-server inter 10s downinter 1m weight 100
    server server1 12.34.56.22:81 check
    server server2 12.34.56.33:81 check

  backend BE-Blah-Img
    # Define some options
    balance roundrobin
    log /dev/log local3
    mode http
    option httplog
    option httpchk /img/login.gif
    option httpclose

    #Active Servers
    default-server inter 10s downinter 1m weight 100
    server server1-en 12.34.56.22:82 check
    server server1-fr 12.34.56.22:84 check
    server server2-en 12.34.56.33:82 check
    server server2-fr 12.34.56.33:84 check

  backend BE-Blah-En
    # Define some options
    balance leastconn
    log /dev/log local3
    mode http
    option httplog
    http-check expect status 200
    option httpchk GET /ServiceCheck/check.aspx?service=english_service
    appsession appCookie len 30 timeout 1d request-learn
    option prefer-last-server
    option http-keep-alive

    #Active Servers
    default-server inter 10s downinter 1m weight 100
    server server1-en 12.34.56.22:82 check
    server server2-en 12.34.56.33:82 check

  backend BE-Blah-Fr
    # Define some options
    balance leastconn
    log /dev/log local3
    mode http
    option httplog
    http-check expect status 200
    option httpchk GET /ServiceCheck/check.aspx?service=french_service
    appsession appCookie len 30 timeout 1d request-learn
    option prefer-last-server
    option http-keep-alive

    #Active Servers
    default-server inter 10s downinter 1m weight 100
    server server1-fr 12.34.56.22:84 check
    server server2-fr 12.34.56.33:84 check


Reply via email to