Forum Discussion
Help with irule using switch
- Jun 04, 2023
veredgfbll I believe what you're looking for is the following. Please keep in mind that you do not have to have the final else or the default action in the switch statement and these are just options if by chance you do have a default action you want to perform for the if statement if it doesn't match or the URI path for the single host match.
when HTTP_REQUEST priority 500 { set URI [string tolower [HTTP::uri]] if { [HTTP::host] == "xxx.com" } { switch -- ${URI} { "/yyy" { # can change http to https if you need to redirect to HTTPS instead HTTP::redirect "http://xxy.com/" } "uri_2" { # URI 2 action to execute } "uri_3" { # URI 3 action to execute } "uri_4" { # URI 4 action to execute } "uri_5" { # URI 5 action to execute } "uri_6" { # URI 6 action to execute } default { # default action to perform if URI doesn't match } } } else { # action to perform if HTTP::host doesn't match } }
- Jun 05, 2023
veredgfbll The iRule you created can be configured as the following which you will notice the "default" match is completely removed since you don't want to perform any other action other than what the iRule and virtual server will already do if a match isn't found.
when HTTP_REQUEST priority 500 { set URI [string tolower [HTTP::uri]] if { [HTTP::host] == "www.hostname.com" } { switch -- ${URI} { "/aaa" { HTTP::respond 302 Location "https://www.test.com/aaa" #log local0. "redirect to https://www.test.com2/aaa completed" } "/aab" { HTTP::respond 302 Location "https://www.test.com/aab" #log local0. "redirect to https://www.test.com2/aab completed" } "/aac" { HTTP::respond 302 Location "https://www.test.com/aac" #log local0. "redirect to https://www.test.com2/aac completed" } "/aad" { HTTP::respond 302 Location "https://www.test.com/aad" #log local0. "redirect to https://www.test.com2/aad completed" } "/aae" { HTTP::respond 302 Location "https://www.test.com/aae" #log local0. "redirect to https://www.test.com2/aae completed" } "/aaf" { HTTP::respond 302 Location "https://www.test.com/aaf" #log local0. "redirect to https://www.test.com2/aaf completed" } "/aag" { HTTP::respond 302 Location "https://www.test.com/aag" #log local0. "redirect to https://www.test.com2/aag completed" } } } }
so I can remove this bit?
default {
# default action to perform if URI doesn't match
return
}
veredgfbll The iRule you created can be configured as the following which you will notice the "default" match is completely removed since you don't want to perform any other action other than what the iRule and virtual server will already do if a match isn't found.
when HTTP_REQUEST priority 500 {
set URI [string tolower [HTTP::uri]]
if { [HTTP::host] == "www.hostname.com" } {
switch -- ${URI} {
"/aaa" {
HTTP::respond 302 Location "https://www.test.com/aaa"
#log local0. "redirect to https://www.test.com2/aaa completed"
}
"/aab" {
HTTP::respond 302 Location "https://www.test.com/aab"
#log local0. "redirect to https://www.test.com2/aab completed"
}
"/aac" {
HTTP::respond 302 Location "https://www.test.com/aac"
#log local0. "redirect to https://www.test.com2/aac completed"
}
"/aad" {
HTTP::respond 302 Location "https://www.test.com/aad"
#log local0. "redirect to https://www.test.com2/aad completed"
}
"/aae" {
HTTP::respond 302 Location "https://www.test.com/aae"
#log local0. "redirect to https://www.test.com2/aae completed"
}
"/aaf" {
HTTP::respond 302 Location "https://www.test.com/aaf"
#log local0. "redirect to https://www.test.com2/aaf completed"
}
"/aag" {
HTTP::respond 302 Location "https://www.test.com/aag"
#log local0. "redirect to https://www.test.com2/aag completed"
}
}
}
}
- veredgfbllJun 06, 2023Cirrus
Thank you very much for clarifying this
Recent Discussions
Related Content
* 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