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.
For one-off cases the replies so far are great and all you need. But if you need to do this in a general case, i.e. multiple substitutions on multiple VIPs, you can consider this rule which should be usable without modification due to its configurability:
Many thanks for your reply - I have tried a version of this, I think my problem is that I want to redirect the host as well as performing a string map to the URI. I’ve tried this:
I 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:
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.