Here is an iRule that I shared with a few customers:
when HTTP_REQUEST {
if { [HTTP::uri] starts_with "/abc"} {
set path [HTTP::uri]
variable loc marks the "Second" occurrence of a '/'. This will drop /abc
if you want to drop /abc/xyz, locate the "Third" occurence of '/' by changing 1 to 2 at
set loc [string first "/" $path 1]
set path_minus_root [string range $path $loc end]
Note: the value of variable path_minus_root will start with a '/'
HTTP::redirect "https://www.company.com/new_site/qux$path_minus_root"
}
}
You can also do this job using the [URI::path [HTTP::uri]] commands which are very useful.
https://devcentral.f5.com/wiki/iRules.URI.ashx