URI::path

Description

Returns the path portion of the given URI.

Syntax

URI::path <uri>
URI::path <uri> depth
URI::path <uri> <starting depth>
URI::path <uri> <starting depth> <ending depth>

URI::path <uri>

  • Returns the path portion of the given URI excluding the basename.

URI::path <uri> depth

  • Returns the path depth.

URI::path <uri> <start>

  • Returns the path portion of the given URI starting from ‘start’.

URI::path <uri> <start> <end>

  • Returns the path portion of the given URI over the range ‘start’ to ‘finish’ (with start >= 1).

Examples

A simple test rule which demonstrates uses of the URI::query commands

when RULE_INIT {

   # You can use URI::query against a static string and not in a client-triggered event!
   log local0. "\[URI::query \"?param1=val1&param2=val2\" param1\]: [URI::query "?param1=val1&param2=val2" param1]"

   # This doesn't work, as URI::query expects a query string to start with a question mark
   log local0. "\[URI::query \"param1=val1&param2=val2\" param1\]: [URI::query "param1=val1&param2=val2" param1]"
}
when HTTP_REQUEST {

   # Log the test URI
   log local0. "\[HTTP::uri\]: [HTTP::uri]"

   log local0. "\[URI::basename \[HTTP::uri\]\]: [URI::basename [HTTP::uri]]"
   log local0. "\[URI::path \[HTTP::uri\]\]: [URI::path [HTTP::uri]]"
   log local0. "\[URI::path \[HTTP::uri\] depth\]: [URI::path [HTTP::uri] depth]"
   log local0. "\[URI::path \[HTTP::uri\] 1\]: [URI::path [HTTP::uri] 1]"
   log local0. "\[URI::path \[HTTP::uri\] 2\]: [URI::path [HTTP::uri] 2]"
   log local0. "\[URI::path \[HTTP::uri\] 3\]: [URI::path [HTTP::uri] 3]"

   # ?
   log local0. "\[URI::path \[HTTP::uri\] 4\]: [URI::path [HTTP::uri] 4]"

   log local0. "\[URI::path \[HTTP::uri\] 1 3\]: [URI::path [HTTP::uri] 1 3]"
   log local0. "\[URI::path \[HTTP::uri\] 2 3\]: [URI::path [HTTP::uri] 2 3]"

   # This isn't a valid range.  The URI depth is 3.  Seems to return the max depth anyhow.
   log local0. "\[URI::path \[HTTP::uri\] 1 4\]: [URI::path [HTTP::uri] 1 4]"

   # This isn't a valid range, so expect a TCL error!  Ranges start with 1.
   log local0. "\[URI::path \[HTTP::uri\] 0 3\]: [URI::path [HTTP::uri] 0 3]"
}

And the corresponding log output:

Rule : [URI::query "?param1=val1&param2=val2" param1]: val1
Rule : [URI::query "param1=val1&param2=val2" param1]:
<HTTP_REQUEST>: [HTTP::uri]: /path/to/file.ext?param=value
<HTTP_REQUEST>: [URI::basename [HTTP::uri]]: file.ext
<HTTP_REQUEST>: [URI::path [HTTP::uri]]: /path/to/
<HTTP_REQUEST>: [URI::path [HTTP::uri] depth]: 2
<HTTP_REQUEST>: [URI::path [HTTP::uri] 1]: /path/to/
<HTTP_REQUEST>: [URI::path [HTTP::uri] 2]: /to/
<HTTP_REQUEST>: [URI::path [HTTP::uri] 3]: /
<HTTP_REQUEST>: [URI::path [HTTP::uri] 4]: /path/to/
<HTTP_REQUEST>: [URI::path [HTTP::uri] 1 3]: /path/to/
<HTTP_REQUEST>: [URI::path [HTTP::uri] 2 3]: /to/
<HTTP_REQUEST>: [URI::path [HTTP::uri] 1 4]: /path/to/
01220001<!--:3: TCL error: test_uri_query_rule <HTTP_REQUEST> - while executing "URI::path [HTTP::uri] 0 3"-->