Forum Discussion

Sirisha_126707's avatar
Sirisha_126707
Icon for Nimbostratus rankNimbostratus
Feb 07, 2017

Redirection

I am new to the iRules , We need to create an irule that forwards requests coming into

 

https://abc.co.uk to go to https://www.xyz.co.uk

 

initially we only need 1 in 10 requests to be forwarded then we will need to increase this number when business requires it until all requests get forwarded to the new address.

 

1 Reply

  • Hi Sirisha,

    you may use the iRule below as a starting point...

    when RULE_INIT {
        set static::load_value 10   ; Load Value in % percent (0-100 is valid)
    }
    when HTTP_REQUEST {
        if { ( [string tolower [HTTP::host]] eq "abc.co.uk" ) 
         and ( [expr { int(rand()*100) }] < $static::load_value } then {
            HTTP::redirect "https://www.xyz.co.uk"
        }   
    }
    

    Note: The

    [expr { int(rand()*100) }]
    syntax generates a random number in the range of
    0-99
    . If the generated number (e.g.
    0-9
    ) is lower than the value of
    $static::load_value
    (e.g.
    10
    ), the request will become redirected to the new URL (e.g. https://www.xyz.co.uk). If the the generated number (e.g.
    10-99
    ) is higher than or equals the value of
    $static::load_value
    (e.g.
    10
    ), the iRule will do nothing and let the request silently pass...

    Cheers, Kai