Forum Discussion
irule to modify hostname in http request and http response
Hi All,
I have a requirement to modify the hostnames on the LTMs. We have an external app and it's accessed from the Internet. Clinets will use https://xyz.com, but the load balanced servers in internal network are configured for the host name - abc.com. So, we need to modify the hostname from xyz.com to abc.com when the LTM sends traffic to the load balanced servers. Also, we need to modify the hostname from abc.com to xyz.com when LTMs sends the return traffic to the client. I am using the following iRule and I would like to know if it will work
when HTTP_REQUEST {
if { ([string tolower [HTTP::host]] equals "xyz.com") }{
# Replace the host header value with abc.com
HTTP::header replace Host "abc.com"
}
}
when HTTP_RESPONSE {
# Replace the host header value with xyz.com
HTTP::header replace Host "xyz.com"
}
I configured the VIP as a standard VIP and SSL termination (client-ssl and server-ssl) is configured. We installed the certificates for xyz.com on the LTM.
I am also looking at rewrite profiles. Article link - https://techdocs.f5.com/kb/en-us/products/big-ip_ltm/manuals/product/ltm-implementations-13-1-0/15.html#guid-62df4df9-a58f-47b0-90e4-a974cf3cd35f I am not sure if I can implement this using rewrite profile.
Thanks.
- Simon_BlakelyEmployee
The irule will work correctly for requests - the Host header will be changed correctly.
However, you do not need to modify a host header in a response, as Host is a request header and not a response header. What you do need to do is modify any references within the response to correct the host (for example, the Location header in a HTTP 302 Redirect response may contain the hostname). Cookies may also contain a domain attribute that needs to be corrected to ensure that the client returns the cookies appropriately.
So using the Rewrite profile is a better approach - otherwise you will probably need to us a STREAM irule to carry out textual substitution of the domain names, which the rewrite profile automates.
- KGNimbostratus
Thanks Blakely. I will try using the rewrite profile. So, can I still use the iRule for requests and use the rewrite profile for responses. Or do you recommend using rewrite profile for both requests and responses. Thanks again.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com