Forum Discussion

skarpovi_111573's avatar
skarpovi_111573
Icon for Nimbostratus rankNimbostratus
Mar 25, 2008

Redirect based on the source IP

Folks, can anyone help.

 

i need something like this:

 

 

when HTTP_REQUEST {

 

if { [TCP::local_port] eq "80" } """ and source IP = 10.x.x.x"""" then redirect to

 

{

 

HTTP::redirect "https://[HTTP::host][HTTP::uri]AAA-link1"

 

}

 

if { [TCP::local_port] eq "80" } """ and source IP = all others"""

 

then redirect to

 

{

 

HTTP::redirect "https://[HTTP::host][HTTP::uri]BBB-link2"

 

 

}else {

 

pool eRoom-Servers-Pool

 

}

 

}

10 Replies

  • Hi,

    Should looks like this:

    
    when HTTP_REQUEST {
      if {([TCP::local_port] eq "80") AND ([IP::client_addr] eq "10.x.x.x") } {
        HTTP::redirect "https://[HTTP::host][HTTP::uri]AAA-link1"
      } elseif {[TCP::local_port] eq "80" } {
         HTTP::redirect "https://[HTTP::host][HTTP::uri]BBB-link2"
      } else {
         pool eRoom-Servers-Pool
      }
    }

  • here is the error i'm getting

     

     

    01070151:3: Rule [rule1] error:

     

    line 4: [parse error: extra characters after close-brace] [else if {[TCP::local_port] eq "80" } {

     

    HTTP::redirect "https://[HTTP::host][HTTP::uri]BBB-link"

     

    }else {

     

    pool Servers-Pool

     

    }

     

    ]

     

    line 6: [undefined procedure: }else] [}else {

     

    pool Servers-Pool

     

    }]
  • This code complie on my bigip, after if you still have issue, i would recommend to use the iRule editor which will help you to troubleshoot syntax

     

     

    
    when HTTP_REQUEST {
      if {([TCP::local_port] eq "80") and ([IP::client_addr] eq "10.2.3.4")} {
        HTTP::redirect "https://[HTTP::host][HTTP::uri]AAA-link1"
      } elseif {[TCP::local_port] eq "80" } {
         HTTP::redirect "https://[HTTP::host][HTTP::uri]BBB-link2"
      } else {
           pool eRoom-Servers-Pool
      } 
    }
  • tried to play with brackets - fixed some errors, but still have some:

     

     

    70151:3: Rule [eRoom-rule] error:

     

    line 2: [parse error: PARSE syntax 53 {syntax error in expression " ([TCP::local_port] eq "80") AND ([IP::client_addr] equals ...": extra tokens at end of expression}] [{ ([TCP::local_port] eq "80") AND ([IP::client_addr] equals "10.0.0.0/16") }]
  • if it's multiple with the same first digits then change:

     

     

    if {([TCP::local_port] eq "80") and ([IP::client_addr] eq "10.2.3.4")} {

     

     

    by

     

     

    if {([TCP::local_port] eq "80") and ([IP::client_addr] starts_with "10.")} {

     

     

    If it's completely different IP addresses then you'll need to use a class and the matchclass command
  • Thanks for help. works with single IP, will try with multiple

     

    by the way, tried to use class. matchclass but wasn't be able to make it work. not sure how and where to define class/matchclass

     

    is it possible to use ([IP::client_addr] eq "10.0.0.0/16")
  • Sorry forgot the matchclass wiki page:

     

     

    Click here

     

     

    and yes you can use the syntax you said but this way:

     

     

    [IP::addr [IP::client_addr]/16 equals 10.0.0.0]