Forum Discussion

Lazaro_Pereira_'s avatar
Lazaro_Pereira_
Icon for Nimbostratus rankNimbostratus
Aug 11, 2014
Solved

iRule to change a take a URL and add URI then send to a Pool.

Hi Everyone,

I have a simple pool selection iRule in place for some internal sites but have been asked to have a URI added at the end to make it easier for people to access. I currently have:

when HTTP_REQUEST {
      switch [string tolower [HTTP::host]] {
        "sharepoint.test-site.com" {
          pool /Internal/F5-Internal-Pool_sharepoint
        }
        default {
          discard
        }
      }
    }

and I would like merge it with something along the lines of :

when HTTP_REQUEST {
        if { [string tolower [HTTP::uri]] equals "/" } {
        HTTP::redirect "https://[HTTP::host]/Pages/default.aspx"
    }

}

How would I merge these two together?

  • Try this one:

        when HTTP_REQUEST {
          switch [string tolower [HTTP::host]] {
            "sharepoint.test-site.com" {
              if { [HTTP::uri] equals "/" } {
               HTTP::redirect "https://[HTTP::host]/Pages/default.aspx"
              }
              else {
               pool /Internal/F5-Internal-Pool_sharepoint
              }
            }
            default {
              discard
            }
          }
        }
    

4 Replies

  • Try this one:

        when HTTP_REQUEST {
          switch [string tolower [HTTP::host]] {
            "sharepoint.test-site.com" {
              if { [HTTP::uri] equals "/" } {
               HTTP::redirect "https://[HTTP::host]/Pages/default.aspx"
              }
              else {
               pool /Internal/F5-Internal-Pool_sharepoint
              }
            }
            default {
              discard
            }
          }
        }
    
  • Any performance impact using if with switch? I just started with iRules and in the 101 they mention how its better to use switch rather than if.

     

  • I don't think you'll encounter any performance issues with the if inside of the switch. Plus it gives you additional flexibility down the road if you want to expand your iRule.