Forum Discussion
Malcom_Sargla_6
Nimbostratus
Oct 12, 2007Simple Http Redirect.. double 'IF' statement
Dear Central..
I am very new to Irules and really could use some assistance with one that I am working on.. again very new so I do apologize in advance if this is very basic.
1) Client request will come in via HTTPs with uri = xxx
2) AND if they belong to proper range within 'test' redirect to external webserver
3) everyone else with uri = xxx is to use default_pool..
when HTTP_REQUEST {
if [HTTP::uri] starts_with $::/xxx } {
if { [matchclass [IP::client_addr] equals $::test] } {
HTTP::redirect "http://xxx.why.not.net/[HTTP::uri]"
} elseif [HTTP::uri] starts_with $::/pfs } {
pool default_pool
}
}
Thank you in advance.
ms.
6 Replies
- Deb_Allen_18Historic F5 AccountThis iRule will redirect only clients in that IP class list who request URI's in that specific path. All other requests (those from other IP addresses or for other URI paths) will go to the default pool:
when HTTP_REQUEST { if {([matchclass [IP::client_addr] equals $::test]) && \ ([string tolower [HTTP::uri]] starts_with "/xxx")}{ HTTP::redirect "http://xxx.why.not.net[HTTP::uri]" } else { pool myPool } }
For this rule to work, you'll need to define a class called "test" of type Address that contains the IP addresses/subnets for which you want to redirect, and the pool myPool must also be defined.
HTH
/deb - Malcom_Sargla_6
Nimbostratus
Dear Deb;
Thank you very much for information. Unfortunately though I cannot seem to get this working though. When connecting via HTTPS I get prompted for the SSL cert but don't actually make it to the destination.
1) https://pfs.swlab.xxx.net/images/1011k.bmp - no dice
however
2) When I go direct the website displays the proper image: http://dev-otasl04.bisb.swlab.xxx.net/images/1011k.bmp
when HTTP_REQUEST {
if {([matchclass [IP::client_addr] equals $::xxxx_test]) && \
([string tolower [HTTP::uri]] starts_with "/pfs")}{
HTTP::redirect "http://dev-otasl04.xxx.swlab.xxx.net[HTTP::uri]"
} else {
pool WTLPERF-updates_8100
}
} - dennypayne
Employee
That's because "pfs" in your example is part of the host, not the URI. So you need:
([string tolower [HTTP::host]] starts_with "pfs")}{
Denny - dennypayne
Employee
EDIT: oops, removed the slash before pfs - Malcom_Sargla_6
Nimbostratus
Hello Deb, Dennypayne;
Thank you for all your assistance with this irule.. works great. Though I do have a couple of questions I was hoping to get some guidance on. If I use ' string tolower' this will lower all incoming url's to lower case, correct? If yes, then this must add some processing overhead to the system. Could I simply remove 'string tolower' and leave the rest of the iRULE intact? Thank you in advance.
when HTTP_REQUEST {
if {([matchclass [IP::client_addr] equals $::xxxx_test]) && \
([string tolower [HTTP::uri]] starts_with "/pfs")}{
HTTP::redirect "http://dev-otasl04.xxx.swlab.xxx.net[HTTP::uri]"
} else {
pool WTLPERF-updates_8100
}
} - Colin_Walker_12Historic F5 AccountThe string tolower command takes whatever information you pass it, HTTP::uri in this case, and turns it into lowercase for the duration of the comparison that's being made.
This means that you can be assured that you're never going to have a mis-match because someone typed "/Pfs" or "/pFS" instead of "/pfs". The web-server might recognize all permutations, but your iRule would fail without the string tolower section.
This command will not, however, have any effect on what the back-end web-servers see. The change is only made for the sake of the comparison in question, and never actually modifies the traffic.
Hope This Helps,
Colin
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
