ALOHA load balancer Redirecting a domain

Target network diagram

an-0009-en-redirecting-a-domain_1_new

Functions to use for ALOHA 5.5.4 and above

Despite the « redirect location » and « redirect prefix » functions are also available in the ALOHA 5.5.4 and above, it is recommended to use their equivalent through « http-request » for an easy reading of the configuration. Parameters are strictly the same for both ways.

http-request redirect location <to> [code <code>] <option> [{if | unless} <condition>]
http-request redirect prefix <to> [code <code>] <option> [{if | unless} <condition>]

Functions to use for ALOHA 3.x until 5.5.3

Redirect location <to> [code <code>] <option> [{if | unless} <condition>]
Redirect prefix <to> [code <code>] <option> [{if | unless} <condition>]

Parameters

Return an HTTP redirection if a condition is met. If no condition is specified, the redirection is applied directly.

Arguments:

<to> this value is placed in the “Location” field of the HTTP header. In the event of a redirection with a prefix, the “Location” field of the HTTP header is created by concatenating “to” and the complete URL, including the query string, unless the “drop-query” option is specified.

<code> The code is optional. It indicates which HTTP redirection type is required. Only codes 301, 302 and 303 are managed. Code 302 is used if no other code is specified.

<option> You can specify several options in order to adapt the expected behavior of a redirection:

drop-query

When this option is used with a redirection based on the prefix, the location will be set without any additional query string.

append-slash

Use this option in conjunction with drop-query in order to redirect users who specify a URL which does not end with “/”. This may be useful for ensuring search engines see only one URL.

set-cookie NAME [=value]

A “set-cookie” header will be added to the response with a name (and “= value” as required). This method is used occasionally to specify that a user has been seen. If no additional options are added, then the cookie will be a session cookie.

clear-cookie NAME [=]

A “set-cookie” header will be added with a name (and “=” as required), but with “MaxAge” set to zero. This option tells the browser to delete this cookie.

Extract of the LB Level7 configuration

######## The first public address as seen by the clients
frontend frt
 bind 10.0.32.10:80 # address:port to listen to
 mode http
 log global # use global log parameters
 option httplog # Enable HTTP logging
 # Detect the host name in the “ mysite.com ” header
 acl detect hr(host) -i mysite.com
 # Redirect "mysite.com" to "www.mysite.com"
 # Until ALOHA 5.5.3
 redirect prefix http://www.mysite.com if detect
 # ALOHA 5.5.4 and above
 http-request redirect prefix http://www.mysite.com if detect
 maxconn 4000 # max conn per instance
 timeout client 25s # maximum client idle time (ms)
 default_backend bck # send everything to this backend by default

####### This backend manages the servers and the load balancing algorithm
backend bck
 balance roundrobin # roundrobin | source | uri | leastconn
 mode http
 log global # use global log parameters
 option httplog # Enable HTTP logging
 cookie SERVERID insert indirect nocache # provide persistence with cookie
 option httpchk HEAD / # how to check those servers
 option forwardfor except 127.0.0.1/8 # add X-Forwarded-For except local
 fullconn 4000 # dynamic limiting below
 timeout server 25s # max server’s response time (ms)
 server srv1 10.0.32.101:80 cookie s1 weight 10 maxconn 100 check inter 1000 fall 3
 server srv2 10.0.32.102:80 cookie s2 weight 10 maxconn 100 check inter 1000 fall 3

Related services - Writing condition rules

To know how to create rules which allow (or not) the redirection, please read the application note #0057 – HTTP Request Routing.

Redirecting a domain

This application note is intended to help you implement a domain redirection from one specific site to another using the ALOHA Load Balancer solution.


Objective

Replace the “mysite.com” domain with “www.mysite.com”


Complexity

2


Versions

v3.x and later