Forum Discussion
gdoyle
Cirrostratus
Oct 03, 2018Multiple URL's redirecting the URI's.
I have a customer that is based out of multiple states, each states website is "mywebsiteXX.com" where XX is the state code (e.g. NY for New York, FL for Florida). All of these come in to the sam...
Lee_Sutcliffe
Nacreous
Oct 04, 2018Your iRule looks fine and should work, but you're repeating two very similar blocks of code. You could achieve the same functionality by using something like this with less lines
when HTTP_REQUEST {
use getfield to capture the first field of the URI
set uriField [string tolower [getfield [HTTP::uri] / 2]]
if {($uriField eq "getstarted") || ($uriField eq "feedback")} {
switch -glob [string tolower [HTTP::host]] {
"*mywebsiteaz*" { HTTP::respond 301 "Location" "https://mywebsiteaz.com/web/xx/$uriField" }
"*mywebsitefl*" { HTTP::respond 301 "Location" "https://mywebsitefl.com/web/xx/$uriField" }
"*mywebsiteny*" { HTTP::respond 301 "Location" "https://mywebsiteny.com/web/xx/$uriField" }
default { discard }
}
}
}You could even do away with the switch statement if you used a datagroup for host to state lookups:
Datagroup:
ltm data-group internal states_dg {
records {
mywebsiteaz {
data az
}
mywebsiteaz {
data fl
}
mywebsiteny {
data ny
}
}
type string
}irule:
when HTTP_REQUEST {
set uriField [string tolower [getfield [HTTP::uri] / 2]]
if {($uriField eq "getstarted") || ($uriField eq "feedback")} {
set state [class match -value [HTTP::host] contains state_dg]
if {$state ne ""} {
HTTP::respond 301 "Location" "https://[HTTP::host]/web/$state/$uriField"
}
}
}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
