Forum Discussion

Rajesh_A_142089's avatar
Rajesh_A_142089
Icon for Nimbostratus rankNimbostratus
Jan 24, 2014
Solved

Conditional Redirection

My use case for iRule:   iRule on Source_Host VIP If Source_Host response is 404 then redirect to Target_Host.   iRule on Target_Host VIP If Current Request is a Redirect and current response i...
  • nitass_89166's avatar
    Jan 25, 2014

    e.g.

    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
    ltm virtual bar {
        destination 172.28.24.10:80
        ip-protocol tcp
        mask 255.255.255.255
        pool foo
        profiles {
            http { }
            tcp { }
        }
        rules {
            qux
        }
        source 0.0.0.0/0
        source-address-translation {
            type automap
        }
        vs-index 8
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo
    ltm pool foo {
        members {
            200.200.200.101:80 {
                address 200.200.200.101
            }
        }
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      if { [HTTP::host] eq "sourcehost.mydomain.com" } {
        set is_sourcehost 1
        set uri [HTTP::uri]
      } else {
        set is_sourcehost 0
      }
    }
    when HTTP_RESPONSE {
      if { $is_sourcehost and [HTTP::status] == 404 } {
        HTTP::respond 302 noserver Location "http://targethost.mydomain.com$uri"
      }
    }
    }
    
    [root@centos1 ~] curl -i http://172.28.24.10/something -H "Host: sourcehost.mydomain.com"
    HTTP/1.0 302 Found
    Location: http://targethost.mydomain.com/something
    Connection: Keep-Alive
    Content-Length: 0