Forum Discussion
John_Ogle_45372
Nimbostratus
Jan 25, 2010URL rewrite (multiple)
I have three virtuals (SAP implmenetation) that need URL rewriting both ways. The client hits app1.company.com/index.html. When it gets passed to a pool member (server), the host field needs to...
hoolio
Cirrostratus
Jan 25, 2010There isn't a host header in responses. If the app uses fully qualified references to itself in response headers (like the Location header in redirects) or in response content (links, forms, etc), you'd need to use a stream profile and iRule to rewrite them.
The proxypass and proxypassv10 iRules (Click here) would allow you to do this type of rewriting. Or for a smaller version, you can try something like the rule below. You'll need to add a blank stream profile to the iRule.
For troubleshooting the rule, you can check the examples on the STREAM::expression wiki page (Click here).
when HTTP_REQUEST {
Check the host header value (set to lowercase)
switch [string tolower [HTTP::host]] {
"app1.company.com" {
Replace the Host header
HTTP::header replace Host "server1.hostname.company.com"
Save the find/replace strings for responses
set internal_host "server1.hostname.company.com"
set external_host "app1.company.com"
}
"app2.company.com" {
Replace the Host header
HTTP::header replace Host "server2.hostname.company.com"
Save the find/replace strings for responses
set internal_host "server2.hostname.company.com"
set external_host "app2.company.com"
}
default {
Take some action for non-matching hosts?
In this example we do nothing to responses if there wasn't a match
set internal_host ""
}
}
If we're potentially going to rewrite the response headers and/or content
prevent the server from sending a compressed response
if {$internal_host ne "" && [HTTP::header exists "Accept-Encoding"]}{
HTTP::header remove Accept-Encoding
}
}
when HTTP_RESPONSE {
Disable the stream filter by default
STREAM::disable
Check if we're potentially rewriting this response
if {$internal_host ne ""}{
Rewrite the Location header for redirects
if {[HTTP::is_redirect]}{
if {[HTTP::header Location] contains "$internal_hostname"}{
HTTP::header replace Location [string map "$internal_hostname $external_hostname" [HTTP::header Location]]
}
}
Rewrite the response content using a stream profile if it is text
if {[HTTP::header Content-Type] contains "text"}{
Set the stream expression with the find/replace strings
STREAM::expression "@$internal_hostname@$external_hostname@"
Enable the stream filter
STREAM::enable
}
}
}
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
