Forum Discussion

John_Lennon_457's avatar
John_Lennon_457
Icon for Nimbostratus rankNimbostratus
Dec 01, 2010

Problem with regexp in HTTP class redirection

I'm following this solution http://support.f5.com/kb/en-us/solutions/public/7000/700/sol7771.html and I created a HTTP Class to redirect like this:

 

 

when URL matches:

 

(?i).*testxyz.*

 

 

redirect to:

 

http://[HTTP::host][string map { testxyz abc/123/mysrv } [HTTP::uri]]

 

 

the goal is to redirect http://myhost.com/testxyz/myres to http://myhost.com/abc/123/mysrv/myres

 

 

This actually works however I have a little annoyance: if a user types a URI like /testxyz/testxyz/testxyz/ the replace appens for each string.

 

 

I can use the slashes around the replace to make sure it's a component of the URI and not partial:

 

http://[HTTP::host][string map { /testxyz/ /abc/123/mysrv/ } [HTTP::uri]]

 

 

but this still doesn't solve my issue.

 

 

What would be the right TLC command / syntax to use in this situation?

 

 

Thanks in advance for your suggestions.

 

1 Reply

  • Hi John,

     

     

    I don't normally recommend regexes as they're a lot more expensive than string commands. However, it would take a lot of string commands to do this in one line. Can you try this?

     

     

    http://[HTTP::host][regsub "find_this_string" [HTTP::uri] "replacement_string"]

     

     

     

    http://www.tcl.tk/man/tcl8.4/TclCmd/regsub.htmM5

     

     

    -all

     

    All ranges in string that match exp are found and substitution is performed for each of these ranges. Without this switch only the first matching range is found and substituted. If -all is specified, then ``&'' and ``\n'' sequences are handled for each substitution using the information from the corresponding match.

     

     

     

    Aaron