Forum Discussion
Issues to forward requests with 'start with' due to similar contexts under same domain
- Jul 15, 2022
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.
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.
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! 🙂
- Jul 15, 2022
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.
- Jul 15, 2022
And if you prefer using regexp for even better granularity you can try this:
when HTTP_REQUEST { switch -regexp -- [HTTP::path] { "(?i)^/cAli(|/|/.*)$" { # log local0. "[HTTP::path] matches /cali and sub segments" set response_string "[HTTP::path] matches /cali and sub segments\r\n" } "(?i)^/califOrnia(|/|/.*)$" { # log local0. "[HTTP::path] matches /california and sub segments" set response_string "[HTTP::path] matches /california and sub segments\r\n" } default { # log local0. "[HTTP::path] not matches regexp" set response_string "[HTTP::path] not matches regexp\r\n" } } HTTP::respond 200 content "${response_string}" noserver Connection Close unset response_string return }
It is:
- case insensitive: '(?i)'
- matching the whole path: '^' to '$'
- looking for specific segment and sub-segments: '(|/|/.*)'
- responding directly for testing purposes by using HTTP::respond
It is important to notice the difference of applying the functions of HTTP::path, HTTP::uri, HTTP::query.
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