Forum Discussion
Aaron_M__Long_1
Nimbostratus
Sep 27, 2012iRule switch confusion (Version 9.4.4)
So I've created an iRule using the switch statement, but for some reason my logic is failing for every conceivable match. Every condition falls through to the default case. What am I doing wrong?...
Kevin_Stewart
Employee
Sep 27, 2012The curly braces around your switch condition causes it fail.
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/storefront/" } {
log local0. "/storefront/"
return
Do nothing
} else {
switch [string tolower [HTTP::uri]] {
"/" -
"/storefront" {
log local0. "/storefront"
HTTP::respond 301 Location "https://[HTTP::host]/storefront/home.ep"
}
"/us.website-sitemap.xml" -
"/uk.website-sitemap.xml" -
"/ca.website-sitemap.xml" -
"/ie.website-sitemap.xml" -
"/au.website-sitemap.xml" -
"/row.website-sitemap.xml" -
"/robots.txt" {
log local0. "xml"
return
}
default {
log local0. "default"
HTTP::respond 301 Location "https://[HTTP::host]/storefront/error.ep?errorCode=404"
}
}
}
}
You also don't need the "" (empty) condition. It'll never happen.
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
