Forum Discussion
Blocking Multiple URLs
Guys,
I want to block the below two URLs using iRule and also I want to log the dropped connections for both the URLs.
/xyz*
/abc
Could you pls let me know what is the iRule?
16 Replies
- What_Lies_Bene1
Cirrostratus
Something like this should work;when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "xyz*" { drop log local0. "Dropped access attempt to [HTTP::uri] from client [IP::client_addr]" } "/abc" { drop log local0. "Dropped access attempt to [HTTP::uri] from client [IP::client_addr]" } default { return } } }
You can use 'reject' instead of 'drop' if you want to actually close the client connection. - What_Lies_Bene1
Cirrostratus
Apologies, I missed the / before xyz* - muzammil_88686
Nimbostratus
Thank you steve for your response!
I have below two rules to the same VS
=====
when HTTP_REQUEST priority 10 {
Check requested content on the header
if {[HTTP::uri] contains "/123"}{
log local0. "/123"
Drop the connection
drop
event disable all}
}=====
when HTTP_REQUEST priority 10 {
switch -glob [HTTP::path] {
"/xyz*" -
"/abc*" -
"/home*" { pool pool1}
default { pool pool2 }
}
}====
Is your suggested rule is still applicable?
- What_Lies_Bene1
Cirrostratus
No it's not. Sorry, can you clearly state which URI's you want to drop as they seem to have changed? Then I'll rewrite the rule. - muzammil_88686
Nimbostratus
I m sorry, the actual URIs are
/xyz*
/123
- What_Lies_Bene1
Cirrostratus
OK, how's this, combining the two;when HTTP_REQUEST { if { switch -glob [string tolower [HTTP::path]] } { "/xyz*" - "/123*" { drop log local0. "Dropped access attempt to [HTTP::uri] from client [IP::client_addr]" return } } elseif { switch -glob [string tolower [HTTP::path]] } { "/abc*" - "/home*" { pool pool1 } default { pool pool2 } } } - muzammil_88686
Nimbostratus
Dear Steve,
Thank you for your response!
I do not want to combine the two iRules as there are multiple statements.
Pls take the below scenario as an example. Also pls ignore the above queries. Pls take it as a new request.
We want to block the below URLs
/123
/xyz/*
Pls note that, we want to exclude the URLs
/xyz/bus*
/xyz/car*
- What_Lies_Bene1
Cirrostratus
OK then, how about this;when HTTP_REQUEST { if { switch -glob [string tolower [HTTP::path]] } { "/xyz/bus*" - "/xyz/car*" { return } } Exit the rule elseif { switch -glob [string tolower [HTTP::path]] } { "/xyz*" - "/123*" { drop log local0. "Dropped access attempt to [HTTP::uri] from client [IP::client_addr]" } } } - muzammil_88686
Nimbostratus
Dear Steve,
I m getting below error on iRule editor
Dear Steve,
I m getting the below error on IRule editor.
line 2: [parse error: PARSE syntax 33 {syntax error in expression " switch -glob [string tolower [HTTP::path]] ": variable references require preceding $}] [{ switch -glob [string tolower [HTTP::path]] }]
line 3: [undefined procedure: /xyz/bus*] ["/xyz/bus*" -]
line 4: [undefined procedure: /xyz/car*] ["/xyz/car*" {
line 8: [undefined procedure: elseif] [elseif { switch -glob [string tolower [HTTP::path]] } {
line 15: [command is not valid in the current scope] [} ] - What_Lies_Bene1
Cirrostratus
Apologies, I think I over engineered it and got some brackets wrong, try this;when HTTP_REQUEST { switch -glob [string tolower [HTTP::path]] "/xyz/bus*" - "/xyz/car*" { return } Exit the rule "/xyz*" - "/123*" { drop log local0. "Dropped access attempt to [HTTP::uri] from client [IP::client_addr]" } }
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
