Forum Discussion

IDEXX_174255's avatar
IDEXX_174255
Icon for Nimbostratus rankNimbostratus
Oct 16, 2014

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

  • 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" 
       }
    
  • 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" }]

     

  • 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" } }

     

  • 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 {

     

  • 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
    }
    
  • 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
    }
    
  • 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"