Rewrite first uri string

Requirement is to rewrite only first uri string.

Eg. https://www.company.com/test/example/test/index.htm to https://www.company.com/testUI/example/test/index.htm

With string map syntax, all “test” in URI part are getting rewrite. also tried split uri to get the first string, set variable and then use string map, but no luck. Can someone please help with any pointer?

Thanks

try this

when HTTP_REQUEST {
    HTTP::uri /[join [lreplace [split [string trimleft [HTTP::uri] /] /] 0 0 "testUI"] /]
}

@Lee - Thanks. This is indeed working as expected.

you can also try this:

when HTTP_REQUEST {
	if {[scan [HTTP::path] "/test/%s" var]} {
		HTTP::path /testUI/$var
	}
}

Nice solution Stan, didn’t think of doing it that way