12-Aug-2021 17:07
Hello
I am trying to redirect http request coming to my F5s to another path, i have a working iRule but the new requirement is, since my VIP has multiple A records, the developers do not know which one is correct therefore i need to change my iRule logic.
I am putting the final destination as a pool in my F5 due to some challenges which we had and by adding the destination in my F5 as a pool we do not have any issue.
can you please check if below iRule is good or do you see any issue, all tree http request for aaa.com bbb.com and ccc.com should go to one endpoint which is api.com
Thanks
Mohammad
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "aaaa.com" } {
HTTP::header replace "Host" "api.com"
set current_uri [HTTP::uri]
HTTP::uri "/something$current_uri"
pool new-pool
}
elseif { [string tolower [HTTP::host]] equals "bbbb.com" } {
HTTP::header replace "Host" "api.com"
set current_uri [HTTP::uri]
HTTP::uri "/something$current_uri"
pool new-pool
}
elseif { [string tolower [HTTP::host]] equals "cccc.com" } {
HTTP::header replace "Host" "api.com"
set current_uri [HTTP::uri]
HTTP::uri "/something$current_uri"
pool new-pool
}
}
13-Aug-2021
04:00
- last edited on
04-Jun-2023
19:20
by
JimmyPackets
I'm assuming you want to send traffic for those 3 hosts to a pool with serverside rewrite and not a clientside redirect (Where URL would be changed and visible to client). So using pool is correct option.
But if traffic for all 3 hosts going to same pool and also there is not other custom requirement for specific host, you can club them together using OR condition. But switch statement would be better.
for last default one you can either use default_pool, reject (reject if host header is coming something diff than defined) or return (to stop processing iRule further and use default assigned pool to vip for other hosts)
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] {
"aaaa.com" -
"bbbb.com" -
"cccc.com"
{
HTTP::header replace "Host" "api.com"
set current_uri [HTTP::uri]
HTTP::uri "/something$current_uri"
pool new-pool
}
default {
return
}
}
}
13-Aug-2021 06:52
Hello Sanjay
Thanks for your recommendation, is the below one correct an issue with this iRule ?
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "aaaa.com"] ||
[string tolower [HTTP::host]] equals "bbbb.com"] ||
[string tolower [HTTP::host]] equals "cccc.com"] } {
HTTP::header replace "Host" "api.com"
set current_uri [HTTP::uri]
HTTP::uri "/something$current_uri"
pool new pool
#log local0. "URI: [HTTP::uri] Host: [HTTP::host]"
}
}
}
13-Aug-2021 07:19
Please use switch command instead, the one I posted above.
13-Aug-2021 07:27
Sure, To increase or my knowledge, Is this iRule also correct or not ?
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "aaaa.com"] ||
[string tolower [HTTP::host]] equals "bbbb.com"] ||
[string tolower [HTTP::host]] equals "cccc.com"] } {
HTTP::header replace "Host" "api.com"
set current_uri [HTTP::uri]
HTTP::uri "/something$current_uri"
pool new pool
#log local0. "URI: [HTTP::uri] Host: [HTTP::host]"
}
}
}
13-Aug-2021 07:51
seems okay. I would just use return command after pool or else to finish the processing of iRule for other host traffic.
13-Aug-2021 10:27
like this ?
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "aaaa.com"] ||
[string tolower [HTTP::host]] equals "bbbb.com"] ||
[string tolower [HTTP::host]] equals "cccc.com"] } {
HTTP::header replace "Host" "api.com"
set current_uri [HTTP::uri]
HTTP::uri "/something$current_uri"
pool new pool
#log local0. "URI: [HTTP::uri] Host: [HTTP::host]"
}
default {
return
}
}
13-Aug-2021
13:23
- last edited on
04-Jun-2023
19:20
by
JimmyPackets
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "aaaa.com"] ||
[string tolower [HTTP::host]] equals "bbbb.com"] ||
[string tolower [HTTP::host]] equals "cccc.com"] } {
HTTP::header replace "Host" "api.com"
set current_uri [HTTP::uri]
HTTP::uri "/something$current_uri"
pool new pool
#log local0. "URI: [HTTP::uri] Host: [HTTP::host]"
return
}
}
}
16-Aug-2021 10:14
Thanks a lot Sanjay