Forum Discussion

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

Problem with regexp in HTTP class redirection

I'm following this solution and I created a HTTP Class to redirect like this:



when URL matches:





redirect to:


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



the goal is to redirect to



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"]








    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.