26-Aug-2021 23:13
Hello iRule Guru
currently i have an iRule that is doing two things, 1: if the http uri has /path1/example/ or /path2/example/ the traffic should go to pool-example
2: then if host equals api.example.com replace the header with host api.newexample.com.
the above conditions are working fine but we discovered that application needs one more condition, the additional condition would be if the uri has version2/sport1 and http method is POST, forward traffic to sport pool, can you please help me to write that condition.
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/path1/example/" or [string tolower [HTTP::uri]] starts_with "/path2/example/"} {
pool pool-example
} elseif { [string tolower [HTTP::host]] equals "api.example.com" } {
HTTP::header replace "Host" "api.newexample.com"
pool api-newexample-com
}
}
Thanks
27-Aug-2021
00:25
- last edited on
21-Nov-2022
16:03
by
JimmyPackets
You can try below code
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "api.example.com" } {
HTTP::header replace "Host" "api.newexample.com"
pool api-newexample-com
return
}
switch -glob [string tolower [HTTP::uri]] {
"/path1/example*" -
"/path2/example*"
{
pool pool-example
}
"/version2/sport1*"
{
if { [HTTP::method] eq "POST"} {
pool sport_pool
} else {
reject
}
} default {
return
}
}
}
27-Aug-2021 00:27
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/path1/example/" or [string tolower [HTTP::uri]] starts_with "/path2/example/"} {
pool pool-example
} elseif { [string tolower [HTTP::host]] equals "api.example.com" } {
HTTP::header replace "Host" "api.newexample.com"
pool api-newexample-com
} elseif { ([HTTP::method] eq "POST") and ([HTTP::uri] contains "version2/sport1") } {
pool sport_pool
}
}