HAProxy reverse proxy config with Pfsense to rewrite a backend server rewritten URL

I have a setup where outside client apps are using a URL with a public IP address PU1.PU2.PU3.PU4 that is reverse proxied by the HAPoxy to the internal URL with private IP address PI1.PI2.PI3.PI4 which is a backend server. I.e. PU1.PU2.PU3.PU4:PORT/Application is transformed into PI1.PI2.PI3.PI4:PORT/Application. The backend server is redirecting the request to a Security Server in order to allow the user to log in and after successful login the user is continuing with the normal URL.
The redirection of the backend server is using the private IP address and this of course does not work for the public access i.e. I get something like PI1.PI2.PI3.PI4:PORT/auth/realms/Applicatiobn/protocol/openid-connect/auth?response_type=code&client_id=myApplicatiob&redirect_uri=http%3A%2F%2FPU1.PU2.PU3.PU4 %3APORT%Application%2Fsso%2Flogin&state=9f8977c9-b3d9-468b-bf91-953267c24681&login=true&scope=openid. Is there a way via actions to script in the transformation of the redirected URL using the public IP Address i.e. changing the private URL to public ?