Forum Discussion

Michael_Powell1's avatar
Michael_Powell1
Icon for Nimbostratus rankNimbostratus
Oct 04, 2010

Redirect dependent on source IP address and URI

Hi there

 

 

I have created the following iRule for a shared application server:

 

 

when HTTP_REQUEST {

 

if {[matchclass [IP::remote_addr] equals $::private_net] && [HTTP::uri] contains "/uri_string_a/"}{

 

return

 

}

 

else {

 

HTTP::redirect "http://www.example.com/"

 

}

 

}

 

 

The intention is to redirect any traffic to a specific uri and not from an internal network to the url www.example.com. However, the iRule is redirecting all traffic for all sites on the application server to the alternative url. Could anyone tell me what I have done wrong please?

 

 

Thanks in advance

 

 

Regards

 

 

Mike

 

2 Replies

  • OK my logic was broken. I wanted to check source IP address and destination URI then permit for a private address and redirect for a public address. Otherwise permit all other traffic. I have resolved it as follows:

     

     

    when HTTP_REQUEST {

     

    if { [matchclass [IP::remote_addr] equals $::private_net] && [HTTP::uri] contains "/uri_string_at/"}{

     

    return

     

    }

     

    elseif {

     

    [HTTP::uri] contains "/uri_string_a/"

     

    }{

     

    HTTP::redirect "http://www.example.com/"

     

    }

     

    else {

     

    return

     

    }

     

    }

     

     

    Thanks anyway for looking :-)
  • Michael, you can leverage CMP by eliminating the "$::" in front of your data group. Also, are you using 9.x or 10.x? If 10, you can also use "class match" instead of "matchclass"