uni
Jul 12, 2006Altostratus
Rewrite redirects to issuing host
I have an https virtual which forwards to an http server, hence I need to rewrite redirects when they point back to the issuing server.
"rewrite all" does not work because the server may issue a redirect to an external http site, and must not be rewritten to https.
"rewrite matching" is not suitable because sometimes the redirect uri does not match the request uri, i.e. a JSESSIONID may be appended to the original uri.
Consequently, I have to come up with an iRule which only rewrites the redirect when the redirection is back to the same host. Could someone have a look at my attempt below and tell me if I'm on the right track?
when HTTP_REQUEST {
set host [HTTP::host];
log LOCAL0.debug "URI=$host";
}
when HTTP_RESPONSE {
if { [HTTP::status] starts_with "3" } {
set location [HTTP::header "Location"];
if { $location starts_with "http://" } {
set temp [substr $location 8];
HTTP::header replace "Location" "https://$temp";
}
}
}