Forum Discussion
jay_41157
Nimbostratus
Dec 17, 2008double wildcard match for uri patterns
Hi,
Is it possible to use 2 wildcards when checking for a uri ?
For ex,
I want to look for
uri1abcURI2zzz
uri1xxxURI2wqq
so for the above can I do....
uri1*xxxURI2*
maybe with reg expressions ?
Thanks,
Jay
- hoolio
Cirrostratus
Hi Jay,string match -nocase "*pattern*" "some string"
switch -glob [string tolower [HTTP::uri]] { "uri1*xxxURI2*" { ...
- jay_41157
Nimbostratus
Aaron, - hoolio
Cirrostratus
If you have multiple patterns you want to check, a switch statement would help keep them organized:when HTTP_REQUEST { Check requested URI switch -glob [HTTP::uri] { "*pattern1* - "*pattern2* - "*pattern3* { Execute this code for the first three patterns HTTP::redirect "http://first_redirect.example.com" } "*pattern4* - "*pattern5* { Execute this code for the next two patterns HTTP::redirect "http://second_redirect.example.com" } default { Execute this code for the any cases that haven't been matched HTTP::redirect "http://default_redirect.example.com" } } }
when HTTP_REQUEST { Check requested URI if { ([string match -nocase "portal/aaa/org/memberapp?*pageLabel=application*" [HTTP::uri] ]) \ or ([string match -nocase "*pattern2*" [HTTP::uri]]) \ or ([string match -nocase "*pattern3*" [HTTP::uri]])}{ log local0. "[IP::client_addr]:[TCP::client_port]: Matched check for [HTTP::uri]" HTTP::redirect http://redirecttotaget } }
- jay_41157
Nimbostratus
great, thanks. which option is more efficient in the irule ? - hoolio
Cirrostratus
I've read in the forums and an old article (Click here) that an if statement is more efficient than a switch for a handful of comparisons. After that a switch is more efficient. At some point (around 100 elements) a datagroup would be more efficient than a switch. I haven't actually tested this before though. - jay_41157
Nimbostratus
I dont think for this specific change we are at the point where speed / resource usage is an issues since this will be in place only for a couple of hours. - jay_41157
Nimbostratus
if i use: - jay_41157
Nimbostratus
the 1st or the second wild card neither of them are matched. - jay_41157
Nimbostratus
using: - hoolio
Cirrostratus
Sorry... I had the pattern and string reversed in my last post. It should be:
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects