I’m trying to configure an iRule that will see if a uri starts with one of two uri’s. If neither uri do a redirect. I have this working for checking one uri but I cannot get it to work when trying to check two uri’s. This is what works for checking one uri:
when HTTP_REQUEST { if { not ([HTTP::uri] starts_with “/test1”) } { redirect to “https://[HTTP::host]/neither-uri-so-redirect-to-this” } }
This is what I am trying with two uri’s which does not work:
when HTTP_REQUEST { if { not ([HTTP::uri] starts_with “/test1” OR “/test2”) } { redirect to “https://[HTTP::host]/neither-uri-so-redirect-to-this” } }
Please let me know if what I am trying to do is possible. Thanks.
Try this:
when HTTP_REQUEST { if { not ([HTTP::uri] starts_with “/test1” or [HTTP::uri] starts_with “/test2”) } { redirect “https://[HTTP::host]/neither-uri-so-redirect-to-this” } }
I usually prefer a switch statement:
when HTTP_REQUEST {
switch -glob [string tolower [HTTP::uri]] {
"/test1*"
"/test2*" { return }
default { HTTP::redirect "https://[HTTP::host]/neither-uri-so-redirect-to-this" }
}
}
Thanks cjunior but that also did not work. I get page cannot be displayed error. I also tried it with the following which also did not work:
when HTTP_REQUEST { if { not ([HTTP::uri] starts_with “/test1” or starts_with “/test2”) } { redirect “https://[HTTP::host]/neither-uri-so-redirect-to-this” } }
try this : when HTTP_REQUEST { if { ! ([HTTP::uri] starts_with “/test1” ) && ! ([HTTP::uri] starts_with “/test2”) } { redirect “https://[HTTP::host]/neither-uri-so-redirect-to-this” } }
try this : when HTTP_REQUEST { if { ! ([HTTP::uri] starts_with “/test1” ) && ! ([HTTP::uri] starts_with “/test2”) } { redirect “https://[HTTP::host]/neither-uri-so-redirect-to-this” } }
when HTTP_REQUEST { if { ! ([HTTP::uri] starts_with “/test1” ) or ! ([HTTP::uri] starts_with “/test2”) } { redirect “https://[HTTP::host]/neither-uri-so-redirect-to-this” } }
when HTTP_REQUEST { if { ! ([HTTP::uri] starts_with “/test1” ) or ! ([HTTP::uri] starts_with “/test2”) } { redirect “https://[HTTP::host]/neither-uri-so-redirect-to-this” } }