Forum Discussion

Vishal_96707's avatar
Vishal_96707
Icon for Nimbostratus rankNimbostratus
Mar 03, 2009

Bypass iRule for specific IP

I have following iRule configured for sharepoint app which redirects to a different site when you get "404" or "File Not Found" error. I want to have a configuration in which the certain ip will bypass the iRule. Even if this specific ip gets "404" or "File Not Found" it is OK.

 

 

Also how do you use IP address match in HTTP request? I believe i will have to use TCP events.

 

 

 
 when HTTP_REQUEST { 
 set MYHOST [HTTP::host] 
 set MYURI [HTTP::uri] 
 } 
  
 when HTTP_RESPONSE { 
 log local0. "HTTP Status code is [HTTP::status] and Content Length is ([HTTP::header value "Content-Length"])" 
 if {([HTTP::status] == 404)} then { 
 log local0. "Found HTTP Status [HTTP::status] and the uri is $MYHOST $MYURI Redirecting" 
 HTTP::redirect "url" 
 } elseif { ([HTTP::payload] contains "File Not Found") or ([HTTP::payload] contains "404 NOT FOUND")  } then { 
 log local0. "Page Content: [HTTP::payload]" 
 HTTP::redirect "url" 
 } 
 } 
 

5 Replies

  •  

    Hi,

     

     

    I'm no expert, but couldn't you use this exemple as a base:

     

    http://devcentral.f5.com/wiki/default.aspx/iRules/AccessControlBasedOnIP.html

     

     

    Doing something like:

     

    if {([HTTP::status] == 404) and not ([matchclass [IP::client_addr] equals $::trustedAddresses]) }{

     

     

  • As benoit suggests, you can use TCP:: and IP:: commands in an HTTP event. The reverse is not always true. For example the HTTP headers have not been parsed by the time CLIENT_ACCEPTED is triggered so you cannot use HTTP:: commands in CLIENT_ACCPEPTED.

     

     

    Aaron
  • sorry i am not expert in programming. Can you help me building other logic?

     

     

    I thought of something like.. i know the "while" option is not present...

     

     

    while not (matchclass matches server ip)

     

    {

     

    if {HTTP::status == 404 condition} {

     

    redirect

     

    }

     

    else {payload condition} {

     

    redirect

     

    }

     

    }

     

     

  • Hi,

    I don't understand, on what do you want to 'while' ?

    If you mean for each client IP address then you need only an if:

     
     if { not [matchclass [IP::remote_addr] equals $::serversIpClass] } { 
      
       if {([HTTP::status] == 404)} then {  
         HTTP::redirect "url"  
       } elseif { ([HTTP::payload] contains "File Not Found") or ([HTTP::payload] contains "404 NOT FOUND")  } then {  
         HTTP::redirect "url"  
       } 
     } 
     } 
     

    or if there is only one exception, something like that:

    if { [IP::remote_addr] not equals "10.0.1.1" }

  • Thanks guys for all your help. I manage to resolve the search crawl issue by bypassing idex server hitting redirection iRule.