Forum Discussion
http redirect with multiple condetion
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
}
}
- spalandeNacreous
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 } } }
- Mohammad_1363Altocumulus
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]"
}
}
}
- spalandeNacreous
Please use switch command instead, the one I posted above.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com