cancel
Showing results for 
Search instead for 
Did you mean: 

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

markmill
Nimbostratus
Nimbostratus

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 3

cjunior
Nacreous
Nacreous

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

 

markmill
Nimbostratus
Nimbostratus

 

 

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

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

 

Cool.

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

 

 Regards.