Forum Discussion
Regular Expression
Hi
I just want that the following Path are valid and sent to the Pool, otherwise the "Forbidden" Message should appear.
/manorbon
/manorbon/
/manorbon/anything
I tested the regex "/manorbon([/]._|[/]?)" on http://regexpal.com/ and it worked as expected but it seems that it doesn't work in the iRule. I always get the Forbidden Message.
If I just use "/manorbon*" it works but also anything starting with /manorbon like /manorbons which i don't want.
iRule: when HTTP_REQUEST {
switch -glob [HTTP::path] {
"/manorbon([/].*|[/]?)" {
SSL::disable serverside
use pool ACA-Pool_appl.com_http
}
default {
HTTP::respond 200 content "Forbidden"
}
} }
is there another way to implement this? Best Regards, Roger
9 Replies
- Kevin_Stewart
Employee
Maybe something simpler will do?
when HTTP_REQUEST { if { ( [string tolower [HTTP::uri]] equals "/manorbon" ) or ( [string tolower [HTTP::uri]] starts_with "/manorbon/" ) } { SSL::disable serverside pool ACA-Pool_app1.com_http } else { HTTP::respond 200 content "Forbidden" } } - aschi_6586
Nimbostratus
Hi Thanks a lot for your answer. That would be a cool solution if I had just one if Statement. But i have choosen the switch statement because I have a lot of different path. I just added one in the sample to keep it simple. Or is possible and best practice to combine switch an if? Best Regards, Roger
- Kevin_Stewart
Employee
Perhaps then a data group:
when HTTP_REQUEST { if { [class match [string tolower [HTTP::uri]] starts_with dc-uri-filter-dg] } { set local_var [class match -name [string tolower [HTTP::uri]] starts_with dc-uri-filter-dg] if { ( [string tolower [HTTP::uri]] equals $local_var ) or ( [string tolower [HTTP::uri]] starts_with "${local_var}/" ) } { SSL::disable serverside pool ACA-Pool_appl.com_http } else { HTTP::respond 200 content "Forbidden" } } }where "dc-uri-filter-dg" is a string-based data group that contains the base URI. Example:
"/manorbon" := "" "/foo" := "" "/bar" := "" "/test" := ""The iRule will match only the defined base URI (equals) or the base URI plus a "/" (starts_with).
- aschi_6586
Nimbostratus
Thanks For the moment i have just 2 different Pools for 10 different Path. I can use If and a elseif for these two Pools. But I think that in the near future I'll have a single Pool for each Path. And that would be a nightmare to administrate with if, elseif, elseif, and so on.
What do you think? Go for the nightmare or another solution? Best Regards, Roger
- Kevin_Stewart
Employee
You could assign the pool names in the data group, then you'd just add the following to the above iRule:
pool [class match -value [string tolower [HTTP::uri]] starts_with dc-uri-filter-dg]And then the only thing you would need to manage is the data group.
- What_Lies_Bene1
Cirrostratus
Just as an aside 'switch -glob' doesn't support full regexs, only glob matching.
- IheartF5_45022
Nacreous
So the simple answer is;
when HTTP_REQUEST { switch -glob [string tolower [HTTP::path]] { "/manorbon" - "/manorbon/*" { SSL::disable serverside pool ACA-Pool_appl.com_http } default { HTTP::respond 200 content "Forbidden" return } } - uni
Altocumulus
Here's a variant of Joanna's response, which could equally be done using if/else:
when HTTP_REQUEST { switch -- [string tolower [getfield [HTTP::path] "/" 2]] { "manorbon" { SSL::disable serverside pool ACA-Pool_appl.com_http } default { HTTP::respond 200 content "Forbidden" return } } } - aschi
Nimbostratus
Thanks a lot, The sample from IheartF5 was exactly what I was looking for. I do not really understand stand the logic of it but it works.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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