I believe the following might be along the lines of what you require:
if (req.url.path ~ "^/a/.+/c") {
set req.url = regsub(req.url.path, "/c", "") + "?" + req.url.qs;
}
It checks if the URL path begins with /a
and is followed by /c
(presuming also that there are segments in-between, such as /b
as per your given example /a/b/c/d
).
Here is a Fastly Fiddle link for you to play around with the code:
https://fiddle.fastlydemo.net/fiddle/527480ba
So given the input URL path:
/a/b/c/d?id=testing
It would change to:
/a/b/d?id=testing
Notice that the /c
has been extracted from the path.