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"
...
Yann_Desmarest
Cirrus
Mar 29, 2016Hello,
The switch condition are taken in the order, so you can define a /dir1* but after /dir1/dir2* for example.
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::path]] {
"/dir1/dir2*" {
HTTP::respond 301 Location "http://www.domain2.com"
}
"/dir1*" {
HTTP::respond 301 Location "http://www.domain1.com"
}
}
}
- ShinRyuXMar 29, 2016
Nimbostratus
Hello, That solution would work but this iRule is actually a simplified version of my current iRule where I have over 100 redirect links along with uri parameters extracted from original URL. I would have to re-order the conditions in ways to prevent any conflicts from occuring. Is there anything that can be done without re-arraging the order? I tried few things like putting "dir1?" or even "dir1[ ?]" but they dont satisfy both conditinos i want. Thank You - Yann_DesmarestMar 29, 2016
Cirrus
What is the logic behind your redirect links ? Maybe, you can extract patterns from your request uri and change the Location value accordingly with a string map command - ShinRyuXMar 29, 2016
Nimbostratus
This is the full logic 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. - ShinRyuXMar 29, 2016
Nimbostratus
See new my new answer Below for the full iRule logic.
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