Forum Discussion
ShinRyuX
Nimbostratus
Mar 29, 2016Any way to shorten this switch case iRule?
Here is my iRule.
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::path]] {
"/dir1" -
"/dir1/" {
HTTP::respond 301 Location "http://www.domain1.com"
...
ShinRyuX
Nimbostratus
Mar 29, 2016My comment on top didnt come out right. Here is the full Logic of my iRule.
when HTTP_REQUEST {
Extract URL parameters
set urlPath "[string tolower [HTTP::path]]?"
if {[string tolower [HTTP::uri]] contains "?"} {
set newUri [string map -nocase [list $urlPath "?"] [HTTP::uri]]
}
else {
set newUri ""
}
Redirection Logic case
switch -glob [string tolower [HTTP::path]] {
"/file1.html" {
HTTP::respond 301 Location "http://www.newdomain.com/en-US/destination1$newUri"
}
"/dir1" -
"/dir1/" {
HTTP::respond 301 Location "http://www.newdomain.com/fr-FR/destination2$newUri"
}
"/dir1/dir2" -
"/dir1/dir2/" {
HTTP::respond 301 Location "http://www.newdomain.com/fr-FR/destination3$newUri"
}
"/dir1/dir2/dir3" -
"/dir1/dir2/dir3/" {
HTTP::respond 301 Location "http://www.newdomain.com/fr-FR/destination4$newUri"
}
...
}
The list goes on but the logic remains the same.
Yann_Desmarest
Cirrus
Mar 29, 2016Maybe you can define a data-group of type string. The string is dirX and the value is destinationX.
Then you apply a trimleft on the HTTP::path to get the last part of the uri, then check the presence of that uri part within the data-group using a command similar to
if { [class match $trimuri equals "uripart_dg" ] } {
HTTP::respond 301 Location "http://www.newdomain.com/fr-FR/[class lookup $trimuri uripart_dg]$newUri"
}
and finally apply th
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