For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

jones618_164217's avatar
jones618_164217
Icon for Nimbostratus rankNimbostratus
Jul 21, 2014

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

  • 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" } }

     

    • Daniel_Suticau_'s avatar
      Daniel_Suticau_
      Icon for Nimbostratus rankNimbostratus

      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" } }

       

  • 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_'s avatar
      Daniel_Suticau_
      Icon for Nimbostratus rankNimbostratus

      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" } }