Forum Discussion
Sam_Parkes_1110
Nimbostratus
Apr 10, 2007Rewrite iRule retaining part of URI
I'm trying to write an iRule that will redirect users from one URI to another - but the parameters passed in need to be retained in the redirect. However the URI is different.
I need it to receiv...
hoolio
Cirrostratus
Apr 12, 2007I missed that you were needing to rewrite the host at the same time. Like kirkbauer noted, you can use the proxypass rule for multiple rewrites. Else for one-off changes to both the host and URI, here are updates for the examples I gave above...
You can use 'string map' (Click here) to rewrite /maps.asp to /VoucherMap.aspx within the complete URI and/or Host header strings.
You can rewrite the requested host and URI before the request is sent to the node with something like this:
when HTTP_REQUEST {
HTTP::header replace Host [string map {oldhost newhost} [string tolower [HTTP::host]]]
HTTP::uri [string map {/maps.asp /VoucherMap.aspx} [HTTP::uri]]
}
Else, if you do want to redirect the client to the new URI, you can use
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/maps"}{
HTTP::redirect "http://[string map {oldhost/maps.asp newhost/VoucherMap.aspx} [string tolower[HTTP::host]][HTTP::uri]]"
}
}
If the web app is sending a 302 redirect, you can check in the HTTP_RESPONSE for a 30x response code and then look in the Location header for /maps and rewrite it to /VoucherMap.aspx.
Lastly, if the web application isn't case sensitive for the URI, you should set the URI to lowercase before making comparisons. I used string tolower to do this for the host header value, as that is not case sensitive for any web app.
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
