Forum Discussion
Kai_Wilke
Jan 08, 2016MVP
Hi Andrea,
you may want to use this PoC code as a starting point...
when RULE_INIT {
set static::local_url "https://www.itacs.de"
set static::local_url_length [string length $static::local_url]
}
when HTTP_REQUEST {
set temp(http_request) [HTTP::request]
set temp(orig_uri) [HTTP::uri]
}
when HTTP_RESPONSE {
if { [HTTP::is_redirect] } then {
set temp(redir_uri) [HTTP::header value Location]
if { ( $temp(redir_uri) starts_with "/" ) } then {
log -noname local0.debug "Following [HTTP::status] HTTP redirect from \"$temp(orig_uri)\" to \"$temp(redir_uri)\""
HTTP::retry [string map [list " $temp(orig_uri) HTTP/" " $temp(redir_uri) HTTP/"] $temp(http_request)]
} elseif { $temp(redir_uri) starts_with $static::local_url } then {
log -noname local0.debug "Following [HTTP::status] HTTP redirect from \"$temp(orig_uri)\" to \"[string range $temp(redir_uri) $static::local_url_length end]\""
HTTP::retry [string map [list " $temp(orig_uri) HTTP/" " [string range $temp(redir_uri) $static::local_url_length end] HTTP/"] $temp(http_request)]
}
}
unset -nocomplain temp
}
The outlined iRule stores your initial [HTTP::request] and [HTTP::uri] during HTTP_REQUEST event and then listens for 301/302 redirect responses during HTTP_RESPONSE event. If the redirect responses are relational to your www-root /* or matching the configured $static::local_url then [HTTP::retry] will be executed using the data of your initial [HTTP::request] but with changed [HTTP::uri] informations.
Cheers, Kai