Forum Discussion
Joe_5599_134300
Nimbostratus
May 03, 2016How can you block/reject subdirectories only, with an irule?
I want to block only the subdirectory and not the default or parent.
This irule I found on Dev Central and some others I have been testing with will also apply the reject to anything before the ...
VernonWells
Employee
May 03, 2016@Yann's use of the
switch is an absolutely sensible approach. I would like to highlight two minor things, however. Firstly, unless your underlying filesystem or the encoded URI-path elements are really case-insensitive, I would advise omitting the string tolower. RFC 3986 says (of URIs in general):
When a URI uses components of the generic syntax, the component
syntax equivalence rules always apply; namely, that the scheme and
host are case-insensitive and therefore should be normalized to
lowercase. For example, the URI is
equivalent to . The other generic syntax
components are assumed to be case-sensitive unless specifically
defined otherwise by the scheme (see Section 6.2.3).
So, unless the filesystem is case-insensitive or the HTTP server provides virtual paths that it handles in a case-insensitive fashion, the
string tolower is extra processing without advantage. Ordinarily, with software, this is fine (and can even be considered good defensive coding) but with iRules, it's generally best to optimize for performance.
I mention this here only because I very often see this pattern. For matching against, say,
HTTP::host, it is needed (as the RFC reference above notes), but for HTTP::path, it often is not.
Secondly, the
default branch in this case is unnecessary (unless you really need to do something in the default case). The extra overhead is very probably negligible (and may even be optimized away). I point it out only to make clear that an explicit default branch is not required for a switch. Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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