Forum Discussion
issue with iRule - client IP and http redirect
Can someone help me fix my error? I'm trying to add to a Big IP version 10.2.2
when HTTP_REQUEST { if {[HTTP::uri] contains "CA" } and {[IP::addr [IP::client_addr] equals 10.10.0.0/21]} { HTTP::redirect "https://public.example.com" } else { HTTP::redirect "https://inside.example.com" }
if {[HTTP::uri] contains "MTN" } and {[IP::addr [IP::client_addr] equals 10.10.0.0/21]} {
HTTP::redirect "https://public.example.com"
} else {
HTTP::redirect "https://inside.example.com"
}
if {[HTTP::uri] contains "UK" } and {[IP::addr [IP::client_addr] equals 172.30.144.0/22]} {
HTTP::redirect "https://public.example.com"
} else {
HTTP::redirect "https://inside.example.com"
}
} else {
discard
}
}
7 Replies
- PeteWhite
Employee
when HTTP_REQUEST { if {[HTTP::uri] contains "CA" && [IP::addr [IP::client_addr] equals 10.10.0.0/21] } { HTTP::redirect "https://public.example.com" } else { HTTP::redirect "https://inside.example.com" } - IDEXX_174255
Nimbostratus
this also gave me a code error.
01070151:3: Rule [clientIP-redirection] error: line 1: [parse error: missing close-brace] [{ if {[HTTP::uri] contains "CA" && [IP::addr [IP::client_addr] equals 10.10.0.0/21] } { HTTP::redirect "https://public.example.com" } else { HTTP::redirect "https://inside.example.com" }] line 2: [command is not valid in the current scope] [if {[HTTP::uri] contains "CA" && [IP::addr [IP::client_addr] equals 10.10.0.0/21] } { HTTP::redirect "https://public.example.com" } else { HTTP::redirect "https://inside.example.com" }]
- IDEXX_174255
Nimbostratus
i figured it out... when HTTP_REQUEST { if { [HTTP::uri] contains "CA" && [IP::addr [IP::client_addr] equals 10.10.0.0/21]}{ HTTP::redirect "https://public.example.com" } else { HTTP::redirect "https://inside.example.com" } }
- IDEXX_174255
Nimbostratus
now I'm getting the error below. can i not add a HTTP_REQUEST on a GTM?
line 2: [unknown event (HTTP_REQUEST)] [when HTTP_REQUEST {
- PeteWhite
Employee
Are you all sorted now?
Presumably the whole thing is something like this:
when HTTP_REQUEST { if { ([HTTP::uri] contains "CA") && ([IP::addr [IP::client_addr] equals 10.10.0.0/21]) } { HTTP::redirect "https://public.example.com" } else { HTTP::redirect "https://inside.example.com" } if { ([HTTP::uri] contains "MTN") && ([IP::addr [IP::client_addr] equals 10.10.0.0/21]) } { HTTP::redirect "https://public.example.com" } else { HTTP::redirect "https://inside.example.com" } if { ([HTTP::uri] contains "UK") && ([IP::addr [IP::client_addr] equals 172.30.144.0/22]) } { HTTP::redirect "https://public.example.com" } else { HTTP::redirect "https://inside.example.com" } discard } - PeteWhite
Employee
Sorry, just looked at the back and it strikes me that you're only ever going to get as far as the else on the first if statement. Presumably you want to use nested if statements instead:
when HTTP_REQUEST { if { ([HTTP::uri] contains "CA") } { if { ([IP::addr [IP::client_addr] equals 10.10.0.0/21]) } { HTTP::redirect "https://public.example.com" } else { HTTP::redirect "https://inside.example.com" } } if { ([HTTP::uri] contains "MTN") { { if { ([IP::addr [IP::client_addr] equals 10.10.0.0/21]) } { HTTP::redirect "https://public.example.com" } else { HTTP::redirect "https://inside.example.com" } } if { ([HTTP::uri] contains "UK") } { if {([IP::addr [IP::client_addr] equals 172.30.144.0/22]) } { HTTP::redirect "https://public.example.com" } else { HTTP::redirect "https://inside.example.com" } } discard } - IDEXX_174255
Nimbostratus
Thank you for the reply. I did figure it out by adding some logging and tailing LTM log. the "HTTP::URI" contains line wasn't determined to be true therefore I modified it to HTTP::host equals. Thank you for your help.
if { [HTTP::host] equals "x.yz.com" and [IP::addr [IP::client_addr] equals 172.16.0.0/16] }{ log local0. "Redirecting to LAN IP" HTTP::redirect "https://internal.example.com" } elseif { [HTTP::host] equals "a.bc.com" }{ log local0. "Redirecting to EXTERNAL" HTTP::redirect "https://external.example.com"
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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
