Forum Discussion
iRule - if HTTP::uri is not one of two uri's redirect everything else
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.
7 Replies
- cjunior
Nacreous
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" } }
- Scott_Hopkins
Nimbostratus
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" } } } - jones618_164217
Nimbostratus
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" } }
- Daniel_Suticau_
Nimbostratus
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" } }
- PK_Bhatia
Nimbostratus
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" } }
- Daniel_Suticau_
Nimbostratus
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" } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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