Forum Discussion
Martijn_Dekkers
Nimbostratus
Jun 15, 2006Matching wildcards in URI
Hi all, I'm new to iRules and could use some help.
I am trying to redirect to https if certain portions of the uri match - a sample uri would be http://testserv/test/folder1/folder2/id=1234
the condition I want to look for is when the uri includes "test" AS WELL AS "id=1234" - the bits in between can change. I have had success looking for just "id=1234" but including the "/test/" is not really working out.
Thanks a million
Martijn
- hoolio
Cirrostratus
Hi Martijn,when HTTP_REQUEST { if { [HTTP::uri] matches_regex "(?i)^\/test\/.*id\=1234" } { log local0. "URI matched regex: [HTTP::uri]" pool http_pool } else { log local0. "URI didn't match regex: [HTTP::uri]" pool other_pool } }
- JRahm
Admin
regex works great, but is a resource hog. You could try:when HTTP_REQUEST { if { ([HTTP::uri] starts_with "/test") and ([HTTP::uri] contains "id=1234") } { HTTP::redirect https://your.host.here } }
- Martijn_Dekkers
Nimbostratus
Hey guys, thanks a lot, this worked great - citizen_elah, can you roll up multiple tests in this? along the lines ofif { ([HTTP::uri] starts_with "/test") and (([HTTP::uri] contains "id=1234") or ([HTTP::uri] contains "id=4567") or ([HTTP::uri] contains "id=8901")) } {
- JRahm
Admin
In the case you will have multiple id=xxxx, I'd build a class:class allowed_ID { "1234" "4567" "8901" }
when HTTP_REQUEST { if { [matchclass [HTTP::uri] contains "$::allowed_ID"] } { if { [HTTP::uri] starts_with "/test" } { HTTP::redirect https://your.host.here } } }
- Martijn_Dekkers
Nimbostratus
citizen_elah - that's awesome, thanks!
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