I’m experiencing a strange looping condition while testing an iRule to match host to redirect to a specific URI in a datagroup. I’m uncertain if this is a web server configuration or something in the iRule?
Curl works, because curl will only do one request. After the first redirect, the following check will match again:
if { [ class match [HTTP::host] equals CC-Host-to-URI-Redirect-DG ] } {
Because it matches, it will do a redirect again. This causes the loop in Chrome. You’ll need to make this if statement more specific. For example also check if [HTTP::uri] equals ‘/’.
So in fact you have to redirect user only when the request URI is different frome the uri in your DG, so try this irule:
when HTTP_REQUEST {
set host [string tolower [HTTP::host]]
set uri [string tolower [HTTP::uri]]
if { [ class match $host equals CC-Host-to-URI-Redirect-DG ] } {
set new_URI [ class match -value $host equals CC-Host-to-URI-Redirect-DG ]
if {!($uri starts_with $new_URI)}{
HTTP::redirect "https://[getfield $host ":" 1]$new_URI"
}
}
}
Additional important point, If you use different POOl by hostname or URI, don’t forget to set an OneConnect profile in order to detach http request.
All, Thank you for the replies and apologies for the delayed response. It was a long weekend and I’m still trying to get used to the new DevCentral.
With that said, I see what you mean about the two match conditions. Also with setting both the HOST and URI. Unfortunately I’m still getting a loop condition when trying the iRule suggested above and matching the plain / prior to redirecting. To rule out caching of the condition I started running Chrome in Incognito mode. I also did attach the default OneConnect profile and that see to work but then I started looping when trying the other URL. Another issue I encountered is if I pasted the full URL it kicked me back to the default which is fine on the initial connection, but don’t want that to happen if someone clicks on a link within the page.
Use case:
Detect host and redirect to specific URI defined in a datagroup. In short I want to be able to use one VS to host multiple specific instances of the same application that are defined with content specific to the URI. I’m going to work on adding logging and use Fiddler to see if I can catch where the loop is.
FYI, I got the following to work via traffic policy; however it’s not using the datagroup which is what I want to have a way to easily add new host to URI mappings without having to add another Rule in the case of traffic policies or iRules. So as Niels van Sluis suggested it seems to be an issue with [HTTP::uri] equals ‘/’. As soon as I added this to the traffic policy my redirect loop stopped.