Forum Discussion

MDPF5_152674's avatar
MDPF5_152674
Icon for Altostratus rankAltostratus
Apr 07, 2016

iRule replace HTTP Host header for virtual Host

Hi DevCentral community.

 

I would like to create an iRule that replaces the HTTP Host header in order to select a virtual host.

 

(watch out there is APM in place)

 

Client request:

 

Host : xxx.test.local

 

F5 to Server:

 

Host : test.it

 

F5 to Client:

 

Host: xxx.test.local

 

Version 11

 

Anyone can help me?

 

Thanks in advance,

 

Best Regards,

 

M.

 

  • Please, can you confirm that the correct iRule events are: Client to server replace : HTTP_REQUEST Server to client replace: HTTP_RESPONSE Thanks
  • The Host header does not return to the client, so HTTP_RESPONSE does not apply.

    Try this

    when HTTP_REQUEST {
        if {[HTTP::host] equals "xxx.test.local"} { [HTTP::host] test.it }
    }
    
  • Try this, it works for me:

    Create a Datagroup partnering Ip + name (SERVER HOST HEADER) from servers you want to load balance.

    After create this, copy this iRule and change "name_datagroup" you have previously created.

    when HTTP_REQUEST_SEND {
    
      clientside {
    
          set host_header_value [class match -value [IP::server_addr] equals **name_datagroup**]
    
            Check if the lookup returned a value
          if {$host_header_value ne ""}{
    
              Replace the host header value
             HTTP::header replace Host $host_header_value
              }
       }
    }