Forum Discussion
Mike_Schnorr_64
Nimbostratus
Oct 05, 2007Improve Big Redirect
I have a redirect rule that has grown into a 180 line case statement. It is getting to be a pain to maintain, so I'd like to put the rules for what redirects where into an data group. It is proving to be more difficult than I thought.
Current rule looks like:
switch -glob [string tolower [HTTP::host]] {
"*domain1.com" {
HTTP::redirect "http://SomeURL1"
}
"*domain2.com" {
HTTP::redirect "http://SomeURL2"
}
"*domain3.com" {
switch -glob [string tolower [HTTP::uri]] {
"/path1*" {
HTTP::redirect "http://SomeURL3"
}
"/path2*" {
HTTP::redirect "http://SomeURL4"
}
default {
HTTP::redirect "http://SomeURL5"
}
}
}
}
Everything except the nested switch seems is fairly straight forward using this rule:
when HTTP_REQUEST {
regsub -nocase www. "[HTTP::host]" "" HostLessWWW
set redirectURL [findclass $HostLessWWW $::redirects " "]
HTTP::redirect "$redirectURL"
}
with this data group:
class redirects {
"domain1.com http://SomeURL1"
"domain2.com http://SomeURL2"
"domain3.com http://SomeURL3"
}
I am stumped trying to expand it to take care of the logic in the nested case statement.
I thought of possibly looping over the findclass call while shrinking the URL from the right. i.e
first loop: domain3.com/dir1/dir2/file1.html
second loop: domain3.com/dir1/dir2
third loop: domain3.com/dir1
fourth loop: domain3.com
If at any point I get a match class I can stop and redirect to the url from findclass. This seems rather clunky and there should be a better way.
Anyone have any ideas?
- Deb_Allen_18Historic F5 AccountThat's the only approach I've been able to come up with so far.
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