Forum Discussion
delvinadm_21686
Nimbostratus
Feb 18, 2009URL Rewrite without Redirect
Hi everybody,
I've got a big problem, which I can't resolv.
The client types in the adressbar:
www.somesiteA.com/AAA
and the Loadbalancer should re...
hoolio
Cirrostratus
Feb 19, 2009For details on the various HTTP:: commands you can check the iRule wiki page:
HTTP:: (Click here)
For a given URL of http://www.example.com:80/path/to/file.ext?param1=value1, you can use the following commands to get/set the values:
HTTP::host - get the host header value (www.example.com:80)
HTTP::header replace Host "newhost.example.com" - set a new host header value
HTTP::uri - get/set the URI (path plus query string: /path/to/file.ext?param1=value1)
HTTP::path - get/set the path (URI minus query string: /path/to/file.ext)
HTTP::query - get the query string (URI minus the path: param1=value1)
If you don't need the full functionality of the ProxyPass iRule, you can do something like this:
when HTTP_REQUEST {
Log a debug line on each request
log local0. "[IP::client_addr]:[TCP::client_port]: New request to [HTTP::host][HTTP::uri]"
Check if the host/path starts with the following string
if {("[string tolower [HTTP::host]][HTTP::path]" starts_with "webservice.xxx.xx/webservice/")}{
Replace the host header
HTTP::header replace Host "ihstestweb.xxx.xx:1234"
Log a debug line on each Host rewrite
log local0. "[IP::client_addr]:[TCP::client_port]: Rewrote Host header from [HTTP::host] to ihstestweb.xxx.xx:1234"
}
}
You may also need to rewrite redirects coming from the application if they contain the internal hostname. If so, you can add this event code:
when HTTP_RESPONSE {
Replace the internal hostname in the HTTP Location header value in redirects
if {[HTTP::is_redirect]}{
log local0. "[IP::client_addr]:[TCP::client_port]: Rewriting redirect from [HTTP::header value Location] to\
[string map {ihstestweb.xxx.xx:1234 webservice.xxx.xx}] [HTTP::header value Location]]"
HTTP::header value Location [string map {ihstestweb.xxx.xx:1234 webservice.xxx.xx}] [HTTP::header value Location]]
}
}
If you only want to replace the host in redirects if the location starts with webservice, you can replace the HTTP::is_redirect check with this:
when HTTP_RESPONSE {
Replace the internal hostname in the HTTP Location header value in redirects
if {[HTTP::is_redirect] && [HTTP::header value "Location"] contains "ihstestweb.xxx.xx:1234/webservice"}{
log local0. "[IP::client_addr]:[TCP::client_port]: Rewriting redirect from [HTTP::header value Location] to\
[string map {ihstestweb.xxx.xx:1234 webservice.xxx.xx}] [HTTP::header value Location]]"
HTTP::header value Location [string map {ihstestweb.xxx.xx:1234 webservice.xxx.xx}] [HTTP::header value Location]]
}
}
If you need to replace the internal hostname within the page content, you can add a stream profile and use the STREAM::expression and STREAM::enable commands to do this. Check the STREAM::expression wiki page (Click here) for details.
Aaron
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
