Forum Discussion

eLeCtRoN's avatar
eLeCtRoN
Icon for Cirrus rankCirrus
Aug 22, 2018

iRule HOST Header replace with dynamic content

Hello,

 

I have just a short question, is it possible and how to change the HOST Header. For example I come from admin.test1.mycompany.com and I would like to change it to admin.test2.mycompany.com, and now the tricky thing, the admin is not static it could be user, steve, georg or what ever be. So the front is dynamic and shout to be carried over. I hope maybe someone can give me a example iRule.

 

cheers

 

Manu

 

4 Replies

  • I’ve written this on my phone so apologies if it’s not 100% correct as I’ve not tested it. This example will take the first field of the Host header up to th first “.” Which in your example is admin, but it could be anything. It then replaces the host header using the test2 host and adding the dynamic first field.

    when HTTP_REQUEST {
        set hostField [getfield [HTTP::host] “.” 1] 
        HTTP::header replace "Host" ${hostField}.test2.mycompany.com
    }
    
  • Thank you guys for the fast answer,so to extend this question, How would the rule look like when I have two dynamic names in the Front ?

     

    Cheers

     

  • This is an amended version, if there is only a first name (second field is "test1") then is will only add the first name. If not, it will add the first two fields to the new host header.

    when HTTP_REQUEST {
        set field1 [getfield [HTTP::host] “.” 1] 
        set field2 [getfield [HTTP::host] “.” 2] 
    
        if {$field2 eq "test1"} {  
            HTTP::header replace "Host" ${hostField}.test2.mycompany.com 
        } else {
            HTTP::header replace "Host" ${field1}.${field2}.test2.mycompany.com
        } 
    }
    
  • Try this:

    when HTTP_REQUEST { 
        HTTP::host [string map {".test1.mycompany.com" ".test2.mycompany.com"} [HTTP::host]]
    }