Forum Discussion
Andrea
Nimbostratus
Jan 05, 2016can big-ip intercepted a redirect
Is it possible to intercept a redirect transparently to the client. keeping the original GET from the URL
Kai_Wilke
MVP
Jan 08, 2016Hi 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
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