Hi, I have studied your request for a while, and I think that I can work it out. However, I have a suggestion to simplify the work: Instead than acting on the Apache server directly, we could proceed as follow:
1) We let the original Apache server listen for the incoming requests on a different port than the default one.
2) Make a newly created HTTP Server listen on the default port on the same ip address. This newly created HTTP server would implement the functions you requested (communication with the remote application, issuing the redirection requests ... and so on). This new HTTP server would always respond with a redirection request, both in case an incoming request has to be redirected to a different server, and in case it has not to be redirected. In the latter case the redirection would be to the original Apache server on its newly assigned TCP port.
Another main question I have is if the "remote application ( the HTTP api used to query for redirection), is already developed or has to be developed as part of the project?".
I currently have installed Apache 2.4 on a linux Debian 8 system, but I could do the development also on other systems if necessary.
Thank you for your attention
Regards
Ciro