Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Answers

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

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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
}
1
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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

0
Comments on this Answer
Comment made 22-Aug-2018 by Lee Sutcliffe 2773

How do you mean two dynamic names? Can you be more specific?

The iRule I provided will dynamically change the host bast on the first field in the host.

But if it’s John.smith.admin1.mycompany.com

It will only carry over the “John”

0
Comment made 22-Aug-2018 by eLeCtRoN 251

Yes this was my question, John.smith would be Dynamic is this possible as well ?

Cheers

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

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
    } 
}
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Try this:

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