Forum Discussion

Darshan_Singh_2's avatar
Darshan_Singh_2
Icon for Nimbostratus rankNimbostratus
Jul 02, 2015

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 } }

 

3 Replies

  • 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

  • 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
      }
    }