Forum Discussion
Andy_Bourke_497
Nimbostratus
Apr 20, 2009Multiple redirects on one VIP
Hi,
We have a virtual server that I've been configuring and I need to write an iRule for some specific functionality.
We have 10 regional sites that all point to one VIP....
hoolio
Cirrostratus
Apr 21, 2009Hi Andy,
It could be a very concise iRule if you use a regex. However, a string function would be more efficient (but longer and less exact). Here are one example for each:
when HTTP_REQUEST {
Log a debug line for every request
log local0. "[IP::client_addr]:[TCP::client_port]: New request to [HTTP::host][HTTP::uri]"
Check if there are any digits in the host header value before a colon,
saving the digits in the $digits variable
if {[regexp {[^0-9:]+([0-9]+)[^0-9]*} [HTTP::host] -> digits]}{
There was at least one digit in the host header value
log local0. "[IP::client_addr]:[TCP::client_port]: Matched: $digits, redirecting."
HTTP::redirect "http://[HTTP::host]/web/app/do.pl?login=auto®ion=$digits"
} else {
There were no digits in the host header value (before a colon). Take some default action?
log local0. "[IP::client_addr]:[TCP::client_port]: No match"
}
}
when HTTP_REQUEST {
Log a debug line for every request
log local0. "[IP::client_addr]:[TCP::client_port]: New request to [HTTP::host][HTTP::uri]"
Redirect based on the host header value
switch [HTTP::host] {
"*1*" {
HTTP::redirect "http://[HTTP::host]/web/app/do.pl?login=auto®ion=1"
log local0. "[IP::client_addr]:[TCP::client_port]: 1"
}
"*2*" {
HTTP::redirect "http://[HTTP::host]/web/app/do.pl?login=auto®ion=2"
log local0. "[IP::client_addr]:[TCP::client_port]: 2"
}
"*3*" {
HTTP::redirect "http://[HTTP::host]/web/app/do.pl?login=auto®ion=3"
log local0. "[IP::client_addr]:[TCP::client_port]: 3"
}
default {
This case will be hit if the request didn't have a digit in the
host header value or didn't have a host header at all.
HTTP::redirect "http://hardcodedhost.example.com/web/app/do.pl?login=auto®ion=default"
log local0. "[IP::client_addr]:[TCP::client_port]: No match, take some default action?"
}
}
}
Aaron
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects