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.

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"
    }
}

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  profiles add { REWRITE }