Forum Discussion
Getting Too Many Redirects error: What is wrong with this iRule?
Hi All,
I wrote an iRule that is correctly redirecting a URL that was sent out by our marketing team that was not correct. The page URL is also case sensitive, and emails were sent out with various cases which is why the new rule was attempted. However, the new rule results in a too many redirects error.
Original rule (WORKS)
when HTTP_REQUEST {
if { [HTTP::uri] contains "solutions/starter-kit" } {
HTTP::redirect https://www.bittitan.com/starter-kit
}
}
New Rule (DOES NOT WORK - TOO MANY REDIRECTS)
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] contains "/starter-kit" } {
HTTP::redirect https://www.company.com/starter-kit
}
}
12 Replies
- Ryannnnnnnnn
Altocumulus
Your new rule is failing because "/starter-kit" exists in the location you are redirecting to https://www.company.com/starter-kit, as such it will keep matching the condition and keep redirecting.
Hi Jgoetsch,
If the casesensitivy is the only problem, then you may want to format the HTTP::uri string tolower before evaluating the old "solutions/starter-kit" condition.
when HTTP_REQUEST { if { [string tolower [HTTP::uri]] contains "solutions/starter-kit" } then { HTTP::redirect https://www.bittitan.com/starter-kit } }
Alternativly you may want to explicitly exempt the correct URI from becomming redirected again.
when HTTP_REQUEST { set low_uri [string tolower [HTTP::uri]] if { $low_uri starts_with "/starter-kit" } then { Do nothing } elseif { $low_uri contains "/starter-kit" } then { HTTP::redirect https://www.bittitan.com/starter-kit } }
Cheers, Kai
- jgoetsch_236444
Nimbostratus
Sorry, neither or these resolve the issue.
Can you clarify whats going wrong with the rules? Is the redirect loop still occouring (dont think so) or does the condition dont match and redirect anymore?
- jgoetsch_236444
Nimbostratus
I get the error "too many redirects" with the below rule:
when HTTP_REQUEST { set low_uri [string tolower [HTTP::uri]] if { $low_uri starts_with "/starter-kit" } then { Do nothing } elseif { $low_uri contains "/starter-kit" } then { HTTP::redirect https://www.bittitan.com/starter-kit }
}
- The iRule looks okay and I'm somewhat sure that the iRule "as is" does't cause a redirect loop to ocour. So you may verify that the server is not sending additional redirects that somehow interfere with the iRule logic?
- jgoetsch_236444
Nimbostratus
Our goal is two fold: 1) for any URI with "solutions/starter-kit", redirect to: https://www.company.com/starter-kit 2) for any URI with "/starter-kit", verify that the URI is lowercase and exactly: https://www.company.com/starter-kit. We can't lowercase all URIs on this Virtual Server because there are other pages that do have upper case letters, we need this only for URIs with 'starter-kit' in the URI.
Hi Jgoetsch,
the previously provided iRule wasn't meant to change the URI on its way to the real server. The [string tolower] command was just included to make the URI comparsion more acurate.
I've updated the rule to reflect your last requirements....
when HTTP_REQUEST { set low_uri [string tolower [HTTP::uri]] if { [HTTP::uri] equals "/starter-kit" } then { Do nothing } elseif { $low_uri equals "/starter-kit" } then { HTTP::uri $low_uri } elseif { $low_uri contains "solutions/starter-kit" } then { HTTP::redirect "https://www.bittitan.com/starter-kit" } }
Hope this helps... 😉
Cheers, Kai
Hi Jgoetsch,
It really depends on your own requirements? If the URI is just "/starter-kit" without any additional deep-links, then "equals" would be fine.
If "/starter-kit" has additional deep-links (e.g. /starter-kit/test?abc=1), that must be formated to lowercase too, then you may want to try this code.
when HTTP_REQUEST { set low_path [string tolower [HTTP::path]] if { $low_path starts_with "/starter-kit" } then { HTTP::path $low_path } elseif { $low_path contains "solutions/starter-kit" } then { HTTP::redirect "https://www.bittitan.com/starter-kit" } }
Remark: Using [string tolower [HTTP::path]] to avoid reformating of potential query (e.g. ?abc=1 ) strings.
Cheers, Kai
- jgoetsch_236444
Nimbostratus
Hi Kai,
I greatly appreciate your responsiveness!
I've put in the below iRule:
when HTTP_REQUEST { set low_uri [string tolower [HTTP::uri]] if { [HTTP::uri] equals "/starter-kit" } then { Do nothing } elseif { $low_uri equals "/starter-kit" } then { HTTP::uri $low_uri } elseif { $low_uri contains "solutions/starter-kit" } then { HTTP::redirect "https://www.bittitan.com/azure-starter-kit" }
}
Results: 1) GOOD - Properly redirects https://www.bittitan.com/solutions/azure-starter-kit to https://www.bittitan.com/azure-starter-kit
2) GOOD - Properly displays https://www.bittitan.com/azure-starter-kit (no too many redirects error)
3) BAD - Still not redirecting URIs with upper-case characters, i.e: https://www.bittitan.com/Azure-starter-kit
NOTE: it is properly redirecting upper case in the 'solutions' portion: i.e.: https://www.bittitan.com/SOLUTIONS/azure-starter-kit to https://www.bittitan.com/azure-starter-kit
So you want to have an additional redirect happen from /AzUrE-stARter-kit to /azure-starter-kit and not a rewrite... 😉
when HTTP_REQUEST { set low_uri [string tolower [HTTP::uri]] if { [HTTP::uri] equals "/azure-starter-kit" } then { Do nothing } elseif { ( $low_uri equals "/azure-starter-kit" ) or ( $low_uri contains "solutions/azure-starter-kit" ) } then { HTTP::redirect "https://www.bittitan.com/azure-starter-kit" } }
Cheers, Kai
Recent Discussions
Related Content
* 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