Forum Discussion
Joe_Pipitone
Nimbostratus
Nov 12, 2009Case insensitive redirects not quite working
I have an iRule that is supposed to do simple redirection if someone types in the following:
http://www.ourdomain.org/LV2010 or http://www.ourdomain.com/lv2010
It seems as though I haven't quite been able to get this to work if I attempt to add anything further past the /LV2010 such as /LV2010/instructors
Can anyone tell me what may be causing this to happen? Here are what the syntax looks like:
if { [string tolower [HTTP::uri]] starts_with "/lv2010" } {
HTTP::redirect "http://www.ourdomain.org/education/display.aspx"
} (THIS WORKS)
if { [string tolower [HTTP::uri]] starts_with "/lv2010/instructors*" } {
HTTP::redirect "http://subdomain.ourdomain.org/events/some-other-file-here-2010/speakers/speaker-list.aspx"
} (THIS DOES NOT WORK)
Any ideas? These need to be case insensitive as well
9 Replies
- Joe_Pipitone
Nimbostratus
Also, if I have a rule such as:if { [string tolower [HTTP::uri]] starts_with "/lv2010/es*" } { HTTP::redirect "http://www.ourdomain.org/education/display.aspx?id=8230" }
Then this does not work:if { [string tolower [HTTP::uri]] starts_with "/lv2010/es/qualify" } { HTTP::redirect "http://subdomain.ourdomain.org/events/some-other-file-here-2010/information/qualification.aspx" } - Colin_Walker_12Historic F5 AccountWhen using the starts_with command you don't need to add an asterisk. It's not a glob style match, the asterisk is implied.
So you'd want to just use:if { [string tolower [HTTP::uri]] starts_with "/lv2010/instructors" } { HTTP::redirect "http://subdomain.ourdomain.org/events/some-other-file-here-2010/speakers/speaker-list.aspx" }
Keep in mind, too, that if you're listing multiple matches you'll want to go from the most specific to the least specific. This is likely why your second post is behaving the way you described. If you match for "/lv2010" then for "/lv2010/es" the first match worked, and the request was already redirected before your second comparison was even performed. If you reverse the order (specific to general) I think you'll see better behavior.
Colin - Joe_Pipitone
Nimbostratus
Thank you! Worked great - Joe_Pipitone
Nimbostratus
I stand corrected - the redirects only work in Chrome - not IE or Firefox, is there anything you see wrong?
Should I be using starts_with in every occurence? I know of an equals and contains?if { [string tolower [HTTP::uri]] starts_with "/lv2010/instructors" } { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/speakers/speaker-list.aspx" } if { [string tolower [HTTP::uri]] starts_with "/lv2010/hotel" } { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/information/hotel-and-travel.aspx" } if { [string tolower [HTTP::uri]] starts_with "/lv2010/register" } { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/information/registration.aspx" } if { [string tolower [HTTP::uri]] starts_with "/lv2010/fax" } { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/information/registration.aspx" } if { [string tolower [HTTP::uri]] starts_with "/lasvegas10" } { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/home.aspx" } if { [string tolower [HTTP::uri]] starts_with "/lasvegas2010" } { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/home.aspx" } if { [string tolower [HTTP::uri]] starts_with "/lv2010/es/register" } { HTTP::redirect "http://events.ourdomain.org/events/some-executive-page-2010/information/registration.aspx" } if { [string tolower [HTTP::uri]] starts_with "/lv2010/es/hotel" } { HTTP::redirect "http://events.ourdomain.org/events/some-executive-page-2010/information/hotel-and-travel.aspx" } if { [string tolower [HTTP::uri]] starts_with "/lv2010/es/qualify" } { HTTP::redirect "http://events.ourdomain.org/events/some-executive-page-2010/information/qualification.aspx" } if { [string tolower [HTTP::uri]] starts_with "/lv2010" } { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/home.aspx" } - The_Bhattman
Nimbostratus
You might want switch from IF to "switch"switch -glob [string tolower [HTTP::uri]] { "/lv2010/instructors*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/speakers/speaker-list.aspx" } "/lv2010/hotel*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/information/hotel-and-travel.aspx" } "/lv2010/register*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/information/registration.aspx" } "/lv2010/fax*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/information/registration.aspx" } "/lasvegas10*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/home.aspx" } "/lasvegas2010*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/home.aspx" } "/lv2010/es/register*" { HTTP::redirect "http://events.ourdomain.org/events/some-executive-page-2010/information/registration.aspx" } "/lv2010/es/hotel*" { HTTP::redirect "http://events.ourdomain.org/events/some-executive-page-2010/information/hotel-and-travel.aspx" } "/lv2010/es/qualify*" { HTTP::redirect "http://events.ourdomain.org/events/some-executive-page-2010/information/qualification.aspx" } "/lv2010*" { HTTP::redirect "http://events.ourdomain.org/events/some-other-page-conference-2010/home.aspx" } }
CB - Joe_Pipitone
Nimbostratus
Are the asterisks required?
Thanks - I'll experiment using switch - Joe_Pipitone
Nimbostratus
FYI this throws an error on the big-ip - i'm using v 9.4.7switch -glob [string tolower[HTTP::uri]] {
throws:01070151:3: Rule [tdwi_caseins_redirects] error: line 4: [wrong args] [string tolower[HTTP::uri]] - Joe_Pipitone
Nimbostratus
CORRECTION - it works fine, it was the needed space between tolower and [ - The_Bhattman
Nimbostratus
I hate it when that happens. :-)
CB
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
