Forum Discussion

awakenings's avatar
awakenings
Icon for Nimbostratus rankNimbostratus
Jul 14, 2022
Solved

Issues to forward requests with 'start with' due to similar contexts under same domain

Hi everybody,

A network request that seemed to be simple is giving some trouble to our network team, I'd appreciate some help.
Here's a summary of the rules to be put in place:

1) example.domain.com/cali --> forward to server1

2) example.domain.com --> forward to server2

When creating the rule with "URI starts with" from web interface it works, but there's a side effect: requests like example.domain.com/california are matching rule 1) and therefore failing, since that context is managed by some Apache at server2.

They've tried using 'IS' instead 'STARTS WITH' for /cali but then, when trailing slash is not added, it fails. It also fails when calling something like /cali/ad
Since we don't know what other possible contexts might be requested, we want just to add a rule for /cali and leave everything else (/california , /calisthenics, ...) under rule 2)

What's the issue here? Is something like it possible just using the web interface or are iRules needed? Any examples?



Thanks a lot in advance

  • Hi awakenings ,

    you might use the regexp, but using globbing is probably less CPU intensive:

    when HTTP_REQUEST {
       # Check the requested path (set to lowercase)
       # -glob: allow string pattern matching
       switch -glob -- [string tolower [HTTP::path]] {
          "/cali" -
          "/cali/" -
          "/cali/*" {
             log local0. "Matched pool 1 paths for [HTTP::uri]"
             pool pool1
          }
          "/california" -
          "/california/" -
          "/california/*"  {
             log local0. "Matched pool 2 paths for [HTTP::uri]"
             pool pool2
          }
          default {
             log local0. "Hit default for [HTTP::uri]"
             pool pool_default
          }
       }
    }
    

    This will send traffic to /cali and following segments to pool1 while traffic to /california and following segments will be forwarded to pool2.

     

4 Replies

  • In case you want to consider multiple URLs for content switching I would recommend using a switch statement with globbing und a non-case sensitive lookup of the URI path.

    Using the switch statement is described here: https://clouddocs.f5.com/api/irules/switch.html.

    Make sure to use OneConnect, to be able to differentiate between requests in the same KeepAlive connection.

     

    • awakenings's avatar
      awakenings
      Icon for Nimbostratus rankNimbostratus

      UPDATE: I just realized I can add just /cali and that should be it

      when HTTP_REQUEST {
      
         # Check the requested path (set to lowercase)
         # -glob: allow string pattern matching
         switch -glob -- [string tolower [HTTP::path]] {
            "/cali" -
      "/cali/*" { log local0. "Matched pool 1 paths for [HTTP::uri]" pool pool1 } default { log local0. "Hit default for [HTTP::uri]" pool pool_default } } }


      Thanks a lot! 🙂

      • Hi awakenings ,

        you might use the regexp, but using globbing is probably less CPU intensive:

        when HTTP_REQUEST {
           # Check the requested path (set to lowercase)
           # -glob: allow string pattern matching
           switch -glob -- [string tolower [HTTP::path]] {
              "/cali" -
              "/cali/" -
              "/cali/*" {
                 log local0. "Matched pool 1 paths for [HTTP::uri]"
                 pool pool1
              }
              "/california" -
              "/california/" -
              "/california/*"  {
                 log local0. "Matched pool 2 paths for [HTTP::uri]"
                 pool pool2
              }
              default {
                 log local0. "Hit default for [HTTP::uri]"
                 pool pool_default
              }
           }
        }
        

        This will send traffic to /cali and following segments to pool1 while traffic to /california and following segments will be forwarded to pool2.