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

Filter by:
  • Solution
  • Technology
Answers

To replace Hostname in HTTP Request and HTTP Response

Hi,

Can we use the following iRule to replace the hostname in the HTTP Request and HTTP Response.

when HTTP_REQUEST{

if { [string tolower [HTTP::host] ] equals "myabc.wxy.com" }{

  HTTP::replace replace Host "replace.wxy.com"

}

}

when HTTP_RESPONSE{

if { [string tolower [HTTP::host] ] equals "replace.wxy.com" }{

  HTTP::header replace "myabc.wxy.com"

}

}

Thanks,

Yugandhar.

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

This should work

when HTTP_REQUEST{
if { [string tolower [HTTP::host] ] equals "myabc.wxy.com" } {
    HTTP::header replace Host "replace.wxy.com"
    }
}
when HTTP_RESPONSE {
    if { [string tolower [HTTP::host] ] equals "replace.wxy.com" }{
      HTTP::header replace Host "myabc.wxy.com"
    }
}
0
Comments on this Answer
Comment made 1 week ago by Yugandhar 72

Thank you Rico.

When i try to create the iRule, I get the following error:-

011c0004:3: Internal rule checker error (malformed error result list).

0
Comment made 1 week ago by Rico 784

That was my mistake, I forgot to change one thing. Since the HTTP::host command is only available in the HTTP_REQUEST event, you must use a different command.

when HTTP_REQUEST{
if { [string tolower [HTTP::host] ] equals "myabc.wxy.com" } {
    HTTP::header replace Host "replace.wxy.com"
    }
}
when HTTP_RESPONSE {
    if { [HTTP::header Host] equals "replace.wxy.com" }{
      HTTP::header replace Host "myabc.wxy.com"
    }
}
0
Comment made 1 week ago by Yugandhar 72

Thank you Rico. This iRule worked for me.

0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Try using a rewrite profile instead of an iRule:

create ltm profile rewrite REWRITE rewrite-mode uri-translation uri-rules add { myabc.wxy.com { type request client { scheme http host myabc.wxy.com path / } server { scheme http host replace.wxy.com path / } } }

modify ltm virtual <VIRTUAL SERVER NAME> profiles add { REWRITE }

0
Comments on this Answer
Comment made 1 week ago by Yugandhar 72

Thank you Michael for providing an alternate way of doing this task.

1