Problem this snippet solves:

This iRule was developed to do HTTP redirects to a particular hostname (defined in a class) for scenarios where you have knowledge of particular source networks that clients are coming from and desire to have these clients directed to a specific hostname.

The virtual server where this iRule lives will typically be accessed following a BIG-IP GTM and ideally, the target hostname is also a BIG-IP GTM Wide-IP where Global Availability is used to deal with the possibility that the sites you are listing in the class file are unavailable.

The advantage of doing this redirection (as opposed to simply letting BIG-IP GTM resolve Wide-IP's using its topology feature) is that rather than GTM where only the Client/Local DNS is visible to GTM; with an iRule running on an LTM virtual server, the actual client IP address is visible. This allows very accurate Source Network based traffic management for scenarios where this is practical.

Code :

class network_to_site_map {
      host { "site5" }
      host { "site4" }
      network { "site1" }
      network { "site2" }
      host { "site3" }
rule source_ipnet_redirector {
   when HTTP_REQUEST {
     set redirecttarget [class match -value [IP::client_addr] equals network_to_site_map]
     if { $redirecttarget ne "")} {
        HTTP::redirect "http://$[HTTP::uri]"
     } else {
        # HTTP::redirect "[HTTP::uri]"
        HTTP::respond 404 content "You're attempting access from an invalid IP address"
Published Mar 18, 2015
Version 1.0

Was this article helpful?

No CommentsBe the first to comment