Forum Discussion
Haroonh
Jun 20, 2020Nimbostratus
Allowing access only to specified directories (HTTP::PATH) on hosts using IRULES
Hi Community, I am a beginner in F5 and would like your help in achieving the following would like to restrict the traffic to only to the following path(s) http://hostname.mylab.co...
PeteWhite
Jun 23, 2020Employee
Cool. I can see what i did wrong:
when HTTP_REQUEST {
if { [HTTP::host] == "hostname.mylab.com" } {
switch -- [HTTP::path] {
"/dir1" -
"/dir2" -
"/dir3" -
"/dir4" { return }
default { drop }
}
} else {
drop
}
}
otherwise, you can implement yours a bit differently:
when HTTP_REQUEST {
set urls { "/dir1*" "/dir2*" "/dir3*" }
if { (! [HTTP::host] eq "hostname.mylab.com") or ( ! [lsearch -glob -- $urls [HTTP::path]) } {
drop
}
}
or if the number of URLs is likely to be a large number ( 20+ ) then you can put them into a datagroup and match against that.
You can also implement this in an LTM policy which would be more performant.
When testing this sort of thing it is a good idea with a range of tests for different urls and formats to check it works as expected, it is easy to find a corner case.
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