Forum Discussion

mbamusa_59409's avatar
mbamusa_59409
Icon for Nimbostratus rankNimbostratus
Jan 03, 2012

HTTP::header replace Irule

hi ;

 

 

if anybody could help me to create an irule to do the following :

 

 

if the url is xxx.com and the pool_member01 was selected the URL should be replaced to yyy.com and

 

if the url is xxx.com and the pool_member02 was selected the URL should be replaced to zzz.com.

 

 

thanks in advance

 

mbamusa

 

2 Replies

  • please feel free to revise.

    [root@ve1023:Active] config  b virtual bar list
    virtual bar {
       snat automap
       pool foo
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve1023:Active] config  b pool foo list
    pool foo {
       members {
          200.200.200.101:80 {}
          200.200.200.102:80 {}
       }
    }
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when LB_SELECTED {
            if {[HTTP::host] equals "xxx.com"} {
                    switch [LB::server addr] {
                            "200.200.200.101" { HTTP::header replace Host "yyy.com" }
                            "200.200.200.102" { HTTP::header replace Host "zzz.com" }
                    }
            }
    }
    }
    
    [root@ve1023:Active] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 172.28.19.253(40646) <-> 172.28.19.79(80)
    1325589266.4184 (0.0038)  C>S
    ---------------------------------------------------------------
    HEAD / HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8r zlib/1.2.3 libidn/0.6.5
    Host: xxx.com
    Accept: */*
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.10(40646) <-> 200.200.200.101(80)
    1325589266.4195 (0.0010)  C>S
    ---------------------------------------------------------------
    HEAD / HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8r zlib/1.2.3 libidn/0.6.5
    Host: yyy.com
    Accept: */*
    ---------------------------------------------------------------
    
    [root@ve1023:Active] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 172.28.19.253(40648) <-> 172.28.19.79(80)
    1325589291.8755 (0.0029)  C>S
    ---------------------------------------------------------------
    HEAD / HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8r zlib/1.2.3 libidn/0.6.5
    Host: xxx.com
    Accept: */*
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.10(40648) <-> 200.200.200.102(80)
    1325589291.8766 (0.0009)  C>S
    ---------------------------------------------------------------
    HEAD / HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8r zlib/1.2.3 libidn/0.6.5
    Host: zzz.com
    Accept: */*
    ---------------------------------------------------------------
    
  • If you want to use a data group to configure the IP to hostname mappings, here's an example you can use:

     

     

    http://devcentral.f5.com/wiki/iRules.rewrite_host_header_to_server_name.ashx

     

     

    Aaron