For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

CraigWoo's avatar
CraigWoo
Icon for Nimbostratus rankNimbostratus
Sep 24, 2022
Solved

simple redirect irule based off ip

Hi All I am very new to irules as we just got our first big-ip this week and have a rookie question for you. I'm trying to redirect a sub-section of a site that I have got working with when HTTP_R...
  • CA_Valli's avatar
    Sep 26, 2022

    Hello, how many networks do you need to match? 

    For allowing multiple client networks you'll need a data group. 

    See this example below - note that "getfield" returns a string so I'm changing the format to IP address using IP::addr .

     

    when HTTP_REQUEST {
      if {[string tolower [HTTP::uri]] starts_with "/restricted1" }{
    
       if { [IP::addr [getfield [IP::client_addr] "%" 1] equals "10.2.2.0/24"]}{
           #this is a sample with a static client network
           return
        } elseif { [class match [getfield [IP::client_addr] "%" 1] equals datagroup_allowed_networks] } {
        #when you have multiple subnet to match, then it is recommended to use data-group created as Address (IP) type. 
           return
        } else {
          HTTP::redirect "https://demo.com/not-allowed"
        }
    }