Reference : Example iRules on BIG-IP Next Central Manager

BIG-IP Next Central Manager provides three iRules to provide a suggestion template for

common uses of an iRule. These iRules are examples provided in BIG-IP Next Central Manager and are not intended for an application service in production.

For more information about managing iRules in BIG-IP Next Central Manager, see How to: Create or modify iRules on BIG-IP Next Central Manager.

For more information about iRule structure, uses, and traffic management customizations see F5 iRule documentation iRules Home.

Example Route To Maintenance Page

An example for routing traffic to a maintenance page when all pool members to an application are down. This iRule is not intended for production use.

# This is an example of an iRule that routes traffic to a maintenance page if all members of the pool are down
when HTTP_REQUEST {
    if { [active_members [LB::server pool]] == 0 } {
# a simple page can be used here for text only
#     HTTP::respond 200 content "Sorry, this page is not currently available."
# or a formatted HTML response can be used:
     HTTP::respond 200 content "
      <html>
         <head>
            <title>Maintenance Page</title>
         </head>
         <body>
            We are sorry, but the site you are looking for is temporarily out of service.
            If you feel you have reached this page in error, please try again.
         </body>
      </html>
      "
    }
}

Example URL Redirect

An example of an iRule used to route traffic to a different page. This iRule is not intended for production use.

# This is an example for an iRule that redirects traffic to http://secure.example2.com/path2 when the browser URL path is http://www.example.com/path1:
when HTTP_REQUEST
 {
  if { [HTTP::host] equals "www.example.com"} {
    if { [HTTP::path] equals "/path1" } {
      HTTP::redirect "http://secure.example2.com/path2"
    }
  }
}

Example Route to Client Info Log Page

An example of an iRule routing traffic to a page that shows client information. This iRule is not intended for production use.

# This is an example of an iRule that routes traffic to a page that shows some information about the client.
when HTTP_REQUEST {
    if { [HTTP::uri] eq "/example-client-info"} {
        set content "<!doctype html>\n<head lang=\"en\">\n<meta charset=\"utf-8\">\n<title>Example Client Info</title>\n</head>\n<body>\n  <h3>Example Client Info</h3>\n    <ul>\n      <li> Virtual server address: [IP::local_addr] </li>\n      <li> Client IP:port: [IP::client_addr]:[TCP::client_port]</li>\n    </ul>\n</body>\n</html>"
        HTTP::respond 200 content $content
    }
}