Shadow
May 06, 2024Cirrus
iRule resulting in too many redirects
I have two requirements with my virtual server.
1. A redirect to /pc/service/SSOLogin
2. 24 hour persistence based on the JSESSIONID cookie in the request header.
The first one was accomplished early on with a policy that redirects to location '/pc/service/SSOLogin' at request time. This has worked without any issues until I tried to implement the JSESSIONID persistence.
To accomplish the second, I created an iRule to be used with the Universal persistence profile. When I implemented this persistence profile, the redirect policy no longer worked. My assumption was that the iRule and the policy were conflicting with each other. To resolve this, I created a single iRule to handle both of these requirements.
Now, I am getting too many redirects. The iRule is below.
when HTTP_RESPONSE {
## PERSISTENCE
# If the JSESSIONID exists, we'll pass the cookie along
if { [HTTP::cookie exists "JSESSIONID"] } {
persist add uie [HTTP::cookie "JSESSIONID"] 86400
}
}
when HTTP_REQUEST {
## PERSISTENCE
# If the JSESSIONID exists, we'll maintain that persistence
if { [HTTP::cookie exists "JSESSIONID"] } {
persist uie [HTTP::cookie "JSESSIONID"]
}
## REDIRECT
# This grabs the base url from the incoming request
# For Example, https://my.site.com/some/path the base_url is set to https://my.site.com
set base_url "https://[HTTP::host]"
# Defining the new path
set new_path "/pc/service/SSOLogin"
# Construct the new URL
# For example, https://my.site.com/pc/service/SSOLogin
set new_url "$base_url$new_path"
# Redirect to the new URL
HTTP::redirect $new_url
}