Forum Discussion
Chris_Schaerli_
Nimbostratus
May 12, 2008Redirect or rewrite?
Hi,
I am trying to setup something to direct traffic based on source IP. We are rolling out an application and we want to do it in phased approach.
This is what I had to start.
when HTTP_REQUEST {
if { [IP::addr [IP::remote_addr] equals 10.32.186.0/255.255.252.0] } {
HTTP::redirect “https://site.com/portal/site/NEW"
} elseif {[IP::addr [IP::remote_addr] equals 10.20.20.0/255.255.252.0] } {
HTTP::redirect http://site.com/portal/site/OLD
} elseif {[IP::addr [IP::remote_addr] equals 10.0.0.0/255.0.0.0] } {
HTTP::redirect "https://site.com/portal/site/OLD"
}
}
I applied this Irule to both VIPS for http://site.com and https://site.com , but I found when I my traffic was looping. I guess I can’t redirect on the same VIP that I want to direct traffic to? Do I have to use a URL instead of a redirect?
when HTTP_REQUEST {
if { [IP::addr [IP::remote_addr] equals 10.32.186.0/255.255.252.0] } {
HTTP:uri "https://site.com/portal/site/NEW"
}elseif {[IP::addr [IP::remote_addr] equals 10.32.186.0/255.255.252.0] } {
HTTP:uri "http://site.com/portal/site/OLD"
} elseif {[IP::addr [IP::remote_addr] equals 10.0.0.0/255.0.0.0] } {
HTTP::uri "https://site.com/portal/site/OLD"
}
}
Thanks,
Chris
- hoolio
Cirrostratus
Hi Chris,when HTTP_REQUEST { if { [IP::addr [IP::remote_addr] equals 10.32.186.0/255.255.252.0] } { Redirect from the HTTP VIP to the HTTPS VIP HTTP::redirect “https://site.com/portal/site/NEW" } elseif {[IP::addr [IP::remote_addr] equals 10.0.0.0/255.0.0.0] } { Redirect from the HTTP VIP to the HTTPS VIP HTTP::redirect "https://site.com/portal/site/OLD" } elseif {[IP::addr [IP::remote_addr] equals 10.20.20.0/255.255.252.0] } { Use the HTTP pool for this request. Or remove this line and the request will go to the default pool on the VIP pool http_pool } }
- Chris_Schaerli_
Nimbostratus
Aaron, - hoolio
Cirrostratus
Hi Chris,when HTTP_REQUEST { if {[HTTP::path] eq "/portl/site/"} if { [IP::addr [IP::remote_addr] equals 10.32.186.0/255.255.252.0] } { Redirect from the HTTP VIP to the HTTPS VIP HTTP::redirect “https://site.com/portal/site/NEW" } elseif {[IP::addr [IP::remote_addr] equals 10.0.0.0/255.0.0.0] } { Redirect from the HTTP VIP to the HTTPS VIP HTTP::redirect "https://site.com/portal/site/OLD" } elseif {[IP::addr [IP::remote_addr] equals 10.20.20.0/255.255.252.0] } { Use the HTTP pool for this request. Or remove this line and the request will go to the default pool on the VIP pool http_pool } } }
- Chris_Schaerli_
Nimbostratus
Aaron, - Colin_Walker_12Historic F5 AccountHere's a slightly cleaned up version. The logic looks correct. I'm not sure why requests would be falling through assuming you have the path and IP correct in the request. Have you tried adding some logging statements to see what values are coming through in your request packets?
when HTTP_REQUEST { if { [string tolower [HTTP::path]] eq "/foo/"} { switch [IP::addr [IP::remote_addr]] { 10.12.126.248/255.255.255.255 - 10.12.126.249/255.255.255.255 - 10.12.126.250/255.255.255.255 - 10.24.69.2/255.255.255.255 - default { pool FOO.com-80 } } } elseif {[IP::addr [IP::remote_addr] equals 10.0.0.0/255.0.0.0] } { HTTP::redirect "http://www.NEW.com"} } }
- Chris_Schaerli_
Nimbostratus
Colin, - Colin_Walker_12Historic F5 AccountThe first line looks fine, but I did make the mistake of assuming that you could use the IP::addr command in this way. Since the IP::addr command takes two arguments, you won't be able to use it in a switch statement. That means you'll have to use a series of if/else comparisons if you want to compare network ranges with multiple destinations. Since your example only uses a single pool as a destination, you could use the or command instead of multiple ifs.
when HTTP_REQUEST { if { [string tolower [HTTP::path]] eq "/foo/"} { switch [IP::remote_addr] { 10.12.126.248 - 10.12.126.249 - 10.12.126.250 - 10.24.69.2 - default { pool FOO.com-80 } } } elseif {[IP::addr [IP::remote_addr] equals 10.0.0.0/255.0.0.0] } { HTTP::redirect "http://www.NEW.com" } }
when HTTP_REQUEST { if { [string tolower [HTTP::path]] eq "/foo/"} { if {([IP::addr [IP::remote_addr] equals 10.12.126.248/255.255.255.255]) or ([IP::addr [IP::remote_addr] equals 10.12.126.249/255.255.255.255]) or ([IP::addr [IP::remote_addr] equals 10.12.126.250/255.255.255.255]) or ([IP::addr [IP::remote_addr] equals 10.24.69.2/255.255.255.255]) } { pool FOO.com-80 } } elseif {[IP::addr [IP::remote_addr] equals 10.0.0.0/255.0.0.0] } { HTTP::redirect "http://www.NEW.com" } }
- Chris_Schaerli_
Nimbostratus
Ok Colin, - Colin_Walker_12Historic F5 Account1.) I don't think you need a regular expression for this kind of match. You can probably achieve this with string commands just as easily. This wouldn't stop the solution from working, just add un-needed overhead.
- Chris_Schaerli_
Nimbostratus
I switched to the matches_regex because the eq never seemed to hit.
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