Forum Discussion
Help with RegEx
I am having some difficulty forming the correct syntax (or regex) for an irule.
I need to block some specific URI's if they come from a specific data group. The logic works, but the regex doesn't.
For example. I need to block any URI that has /admin or /admin/ or /user or /user/ BUT (and this is where it's not working) if the URI= /user-experience then it needs to work.
I've used REGEX that looks like
elseif {([HTTP::uri] matches_regex "^(/admin/|/user/|/?q=admin|/?q=admin|/?q=user|/?q=user) and ([class match [IP::client_addr] equals block_ip])} {
And I've used a bunch of different "starts_with" and "equals" but strangely enough whenever I block "user" it blocks user-experience. Even if I use the "equals" URI. Which I don't understand b/c /user-experience doesn't equal /user.
I'm sure there is something simple here...any help would be appreciated.
Thanks in advance
regex in iRule equals bad news. Try something like this:
elseif { [class match [IP::client_addr] equals block_ip] }{ switch -glob [string tolower [HTTP::uri]] { "/user-experience*" { return } "/user*" - "/admin*" { reject } default { return } } }
- Brad_ParkerCirrus
regex in iRule equals bad news. Try something like this:
elseif { [class match [IP::client_addr] equals block_ip] }{ switch -glob [string tolower [HTTP::uri]] { "/user-experience*" { return } "/user*" - "/admin*" { reject } default { return } } }
- dp_119903Cirrostratusthat worked well. Thanks
- Brad_Parker_139Nacreous
regex in iRule equals bad news. Try something like this:
elseif { [class match [IP::client_addr] equals block_ip] }{ switch -glob [string tolower [HTTP::uri]] { "/user-experience*" { return } "/user*" - "/admin*" { reject } default { return } } }
- dp_119903Cirrostratusthat worked well. Thanks
- dp_119903Cirrostratus
I did this and it worked...I'll give the above a shot.
when HTTP_REQUEST { if { not ( [class match [IP::client_addr] equals first_data_group] ) } { reject } elseif {([HTTP::uri] starts_with "/admin") and ([class match [IP::client_addr] equals second_data_group])} { reject } elseif {([HTTP::uri] equals "/user") and ([class match [IP::client_addr] equals second_data_group])} { reject } elseif {([HTTP::uri] equals "/user/") and ([class match [IP::client_addr] equals second_data_group])} { reject } elseif {([HTTP::uri] contains "/?q=admin"|"/?q=user") and ([class match [IP::client_addr] equals second_data_group])} { reject } }
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