Forum Discussion
http redirect with multiple condetion
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
}
}
}
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]"
}
}
}
- spalandeAug 13, 2021Nacreous
Please use switch command instead, the one I posted above.
- Mohammad_1363Aug 13, 2021Altocumulus
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]"
}
}
}
- spalandeAug 13, 2021Nacreous
seems okay. I would just use return command after pool or else to finish the processing of iRule for other host traffic.
- Mohammad_1363Aug 13, 2021Altocumulus
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
}
}
- spalandeAug 13, 2021Nacreous
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 } } }
- Mohammad_1363Aug 16, 2021Altocumulus
Thanks a lot Sanjay
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