
How to create irule in F5
On the Main tab, click Local Traffic > iRules.
Click Create.
In the Name field, type a name, such as my_irule
Example :
Just example if we want to redirect http://xyz.com its redirect to https://xyz.com
when HTTP_REQUEST {
if { equals "xyz.com"} {
HTTP::redirect "https://"
}
}
Nexp step - Add the iRule to your HTTP virtual server in the "Resouces" tab/section
Note : instead of equals you can use other operators from "equals" to "starts_with", "contains", and "ends_with".
------
Next IRULEwe can use based on Cookies value we can use backed servers or forward traffic.
Please note : log local0. only used for logs purpose once you done your testing you can remove this because its generate huge logs.
Example :
Pool Name- Test_POOL_HTTP
Pool member ip - 192.168.1.1:80, 192.168.1.2:80
Cookies value: xyz, abc
-------------------------------------------------------------------------------------------------------------------
when HTTP_REQUEST {
log local0. "HTTP Rquest RECEIVED"
log local0. ""
if { } {
if { contains "xyz" } {
if { eq "up" } {
pool Test_POOL_HTTP member 192.168.1.1 80
}
else {
pool Test_POOL_HTTP member 192.168.1.2 80
}
log local0. " and user has gone to specific 192.168.1.1-------Client Connected, IP: "
}
elseif { contains "abc" } {
if { Test_POOL_HTTP member 192.168.1.2 80="> 80"> eq "up" } {
pool Test_POOL_HTTP member 192.168.1.2 80
}
else {
pool Test_POOL_HTTP member 192.168.1.1 80
}
log local0. " and user has gone to specific 192.168.1.2-----Client Connected, IP: "
}
else {
pool Test_POOL_HTTP member 192.168.1.1 80
}
; }
}
---------------------------------------------------------------