I think your mistake may be that you replace the whole URI with a constant (/version04.webservices.info/). Everything in the URI will be replaced by this. Try to insert a log sentence and explore what happens.
You can solve this with a regsub command or the like. I don’t garante the syntax but I hope you get the idea :-).
Example
when HTTP_REQUEST {
if {[HTTP::uri] starts_with “/portal/”} {
log local0. “Original HTTP uri = [HTTP::uri]”
set [HTTP::uri] [regsub -all ^/portal [HTTP::uri] “/version02.webservices.portal”]
HTTP::uri refers to the entire URI, including the query string. So when you are setting the URI with HTTP::uri “/version02.webservices.portal/” or HTTP::uri “/version04.webservices.info/”, you are overwriting the entire URI.
If you want to replace the instance of /portal/ with /version02.webservices.portal/ and leave the rest of the URI intact, you can use string map:
You can also view the timing statistics (cpu cycles) with the new F5 iRule Editor. Right click on an iRule in the list and select the “Properties” menu item and then select the Statistics tab.
It looks like HTTP::uri only refers to the original client request. Perhaps one of the gurus can explain this.
I used the following to verify the rewrite though:
when HTTP_REQUEST {
set debug to 1 to enable logging to /var/log/ltm. Set to 0 to disable logging.
set debug 1
if { [HTTP::uri] contains "uri1" } {
HTTP::uri [string map { uri1 uri2 } [HTTP::uri]]
if {$debug}{
log local0. "Rewrote URI from: [HTTP::uri]"
log local0. 'Rewrote URI to: [string map { uri1 uri2 } [HTTP::uri]]"
}
}
}
I’ve see this behavior before as well. Maybe unRuleY could comment on why it is but I’ve verified that the URI is correctly changed with the HTTP::uri command but the contents of the variable isn’t correctly updated to match. Maybe this has something to do with variable caching but I’m not sure. If you want to log the values, store it into a temporary variable.
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/portal/" } {
log local0. "Original HTTP uri = [HTTP::uri]"
set newUri [string map { /portal/ /version02.webservices.portal/ } [HTTP::uri]]
HTTP::uri $newUri
log local0. "New HTTP uri = $newUri"
pool SDS_Pool01
}