Forum Discussion
Stephen_Swali_8
Jan 17, 2008Nimbostratus
iRule to change host headers.
Hi guys,
first time on DC so apologies in advance if I'm doing something wrong.
Please can you help with an issue I have.
We have a website that is hosted externally on a...
hooleylist
Jan 17, 2008Cirrostratus
Hi Steve,
If the response content from the external site contained absolute references to the external domain, then you would want to rewrite these to the internal domain before sending the response back to the client. To do this, you can use the STREAM:: commands. Looking at the external host you had listed, I didn't see any embedded references (href's, img src, etc) to the external site, so I think this is unnecessary in your situation. You could double check this though.
You can combine the two rules you have listed above into a single rule. Also, you can do a case insensitive comparison for the host using string compare. Lastly, you can redirect / to /aon.asp. Here is an untested example:
when RULE_INIT {
Set the hostname that the client makes request to (do not include protocol)
set ::external_hostname "www.mycompany.co.uk"
Set the hostname that the BIG-IP will rewrite requests to
set ::internal_hostname "www.provider.com"
Redirect / requests to this URI
set ::root_redirect_uri "/aon.asp"
Log debug messages to /var/log/ltm? 1=yes, 0=no.
set ::proxy_site_debug 1
}
when HTTP_REQUEST {
if {$::proxy_site_debug}{log local0. "Received request from [IP::client_addr] -> [HTTP::host][HTTP::uri]"}
Check if request is to root document
if {[HTTP::path] eq "/"}{
if {$::proxy_site_debug}{log local0. \
"Redirecting [IP::client_addr] from / -> https://$::external_hostname$::root_redirect_uri"}
Redirect to internal hostname and root object
HTTP::redirect "https://$::external_hostname$::root_redirect_uri"
} else {
if {$::proxy_site_debug}{log local0. "Rewriting [IP::client_addr]'s Host header to $::internal_hostname"}
We're not redirecting so 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 to \
[string map -nocase $::internal_hostname $::external_hostname [HTTP::header Location]]"}
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]]
}
}
Aaron
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