Forum Discussion

markmill's avatar
markmill
Icon for Nimbostratus rankNimbostratus
May 30, 2020

Combine URI::path and URI:basename in single TCL command string

I have a uri /dir1/dir2/dir3/filename.ext where I would like to replace/strip the first directory e.g. /dir2/dir3/filename.ext before forwarding on the request. I have been using the following, but I'm struggling with how to pass the URI::basename along as well. I'm looking for a single TCL command string that I can use within my LTM traffic policy.

tcl:[URI::path [HTTP::uri] 2]

3 Replies

  • Hi,

    Is the /dir1 a fixed name?

    If so, you can simply skip that name length:

    tcl:[string range [HTTP::uri] 5 end]

    Otherwise, you can work with variables or try this single line:

    tcl:[URI::path [HTTP::uri] 2][URI::basename [HTTP::uri]][expr { \"[URI::query [HTTP::uri]]\" eq {} ? {} : \"?[URI::query [HTTP::uri]]\" }]

    I hope it helps.

    Regards

  • The following is what I was looking for. Thanks for the assistance

    tcl:[URI::path [HTTP::uri] 2][URI::basename [HTTP::uri]]
    • cjunior's avatar
      cjunior
      Icon for Nacreous rankNacreous

      Cool.

      Just keep in mind you are discarding query string parameters and values.

       

       Regards.