Forum Discussion
johnscr_45871
Nimbostratus
Dec 12, 2008Simple match of URL based on regular expression
Hi
I am haveing some trouble with this simple Irule and was hoping someone could help. All I have to do is check the incomming URL and see if it matches a reg ex. If it matches the reg ...
hoolio
Cirrostratus
Dec 12, 2008Hi there,
A string comparison would be more efficient than a regex. If you really want to check if the postcode and email parameters are in the URI in a particular order you could use [string match *postcode=*email=* [HTTP::query]] to perform the test. Else if you want to check if the query string contains the two parameters in any order you could do two checks ([string match *postcode=*email=* [HTTP::query]] or [string match *email=*postcode=* [HTTP::query]]) or parse the parameters using URI::query (Click here)
Here is the first option:
when HTTP_REQUEST {
Check if the query string contains anything postcode anything email anything or anything email anything postcode
if {([string match *postcode=*email=* [HTTP::query]] or [string match *email=*postcode=* [HTTP::query]])}{
Query string matched, so use PoolB
pool PoolB
} else {
Query string did not match, so use PoolA
pool PoolA
}
}
Here is the second option which parses the query string for the actual parameter values and checks if they have a length. If you don't care whether the parameters have a value, you can remove the string length check on the values:
when HTTP_REQUEST {
Check if the query string contains the postcode and email email parameters with lengths
if {([string length [URI::query [HTTP::query] postcode]] and [string length [URI::query [HTTP::query] email]])}{
Query string matched, so use PoolB
pool PoolB
} else {
Query string did not match, so use PoolA
pool PoolA
}
}
Aaron
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
