Make a proxy app (it's no different from normal HTTP server from client POV), check the HTTP_HOST and REQUEST_URI headers, if they match the URL you want to redirect, then modify them and forward the request to the address you want. Point the browser's proxy to your proxy app. Something like:
{$mode objfpc}
uses
fphttpapp,httproute,httpdefs,fphttpclient;
procedure RedirectIfMatches(ARequest : TRequest; AResponse : TResponse);
var
Client: TFPHTTPClient;
begin
Client := TFPHTTPClient.Create(nil);
try
if (ARequest.Method = 'POST') and (ARequest.URL = 'http://127.0.0.1/xxxx') then begin
// redirect request
AResponse.Content := Client.Post('http://y.y.y.y:zzzz');
end else begin
// forward request, note that this discards headers and body that might present in the request
case ARequest.Method of
'GET': AResponse.Content := Client.Get(ARequest.URL);
'POST': AResponse.Content := Client.Post(ARequest.URL);
// complete the other methods
end;
end;
finally
Client.Free;
end;
end;
begin
HTTPRouter.RegisterRoute('*path',@RedirectIfMatches);
Application.Port := 8888;
Application.Initialize;
Application.Run;
end.