Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Clear all filters
Answers

iRule to drop if uri starts with specific word.

Customer have requiment that if there URI starts with /abc/* then drop the request.

For this I created below iRule after applying this all traffic was getting drop. Please suggest what I missed.

when HTTP_REQUEST { set lowerCaseUri [ string tolower [HTTP::uri] ] if { ($lowerCaseUri starts_with "/abc") } { reject } }

0
Rate this Question

Answers to this Question

placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

The only thing I see is that you specified you wanted anything starting with "/abc/" to be rejected. In the iRule you have anything starting with "/abc". Not sure if that's what you intended or not. I couldn't save that iRule as-is due to parsing errors. Try this

when HTTP_REQUEST {
  if { [string tolower [HTTP::uri]] starts_with "/abc/" } {
    log local0. "Rejecting "/abc/* request"
    reject
  }
}

This should print a message to the /var/log/messages file everytime a /abc/* request comes in. /var/log/messages should also print out any errors you are having.

-Joe

0
Comments on this Answer
Comment made 02-Jun-2016 by Root44 390
Hi Joe, Can I use "contains" in the place of "starts_with" ? and after dropping the traffic with that URI, I want send rest of the traffic to my default pool. Also, "log local0. "Rejecting "/abc/* request" " will log the rejecting requests in the local0. ? (just for my understanding, as I am new to iRules)
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

You can certainly use "contains" instead of "starts_with" but will it achieve the functionality that you are seeking ? I think you need to discuss with the customer to understand the function required and also inform him of what exactly your iRule will do before implementing.

I would recommend logging the actual URI that is being dropped to compare:

Using Joe's iRule:

when HTTP_REQUEST {
  if { [string tolower [HTTP::uri]] starts_with "/abc/" } {
    log local0. "Rejecting [HTTP::uri] request"
    reject
  }
}
0
placeholder+image
USER ACCEPTED ANSWER & F5 ACCEPTED ANSWER

Hi, can we use http::URI starts_with and give a list of string instead? Jerodingo

0