Forum Discussion
ghost-rider_124
Nimbostratus
Jul 15, 2014How many ways to rewrite http request and response for hostname, port and URI rewrite
Hello Experts
I need to mask the URL between virtual server on f5 and backend servers. The URL on backend server is http://server1xls.abc.com:8040/OA_HTML/AppsLogin and the URI on F5 should be h...
John_Antony_162
Nimbostratus
Sep 04, 2015it's been a while someone answered this. But I had a similar situation and below iRule worked great
when RULE_INIT {
Set the hostname that the client makes request to (do not include protocol)
set ::external_hostname "external.com"
Set the hostname that the BIG-IP will rewrite requests to
set ::internal_hostname "server1.local.intra:8445"
Log debug messages to /var/log/ltm? 1=yes, 0=no.
set ::proxy_site_debug 0
}
when HTTP_REQUEST {
if {$::proxy_site_debug}{log local0. "Received request from [IP::client_addr] -> [HTTP::host][HTTP::uri]"}
if {$::proxy_site_debug}{log local0. "Rewriting [IP::client_addr]'s Host header to $::internal_hostname"}
Rewrite the Host header
HTTP::header replace "Host" $::internal_hostname
}
when HTTP_RESPONSE {
Check if the status indicates a redirect
if {[HTTP::is_redirect]} {
if {$::proxy_site_debug}{log local0. "Rewriting [IP::client_addr]'s redirect"}
Rewrite the Location header replacing the internal hostname with the external hostname
HTTP::header replace Location [string map -nocase {$::internal_hostname $::external_hostname} [HTTP::header Location]]
}
}
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects