Slim 3 - URI path not parsed correctly

When my request goes through proxy then the request log in apache looks like this:
18.215.58.36 - - [21/Apr/2020:09:49:14 +0000] “POST https://api.xxx.com:443/xxx/add HTTP/1.1” 404 4366 “-” “GuzzleHttp/6.5.1 curl/7.58.0 PHP/7.3.16-1+ubuntu18.04.1+deb.sury.org+1”

In this case the URI path is not parsed correctly:
object(Slim\Http\Uri)#34 (9) {
[“scheme”:protected]=>
string(5) “https”
[“user”:protected]=>
string(0) “”
[“password”:protected]=>
string(0) “”
[“host”:protected]=>
string(17) “api.xxx.com
[“port”:protected]=>
int(443)
[“basePath”:protected]=>
string(0) “”
[“path”:protected]=>
string(41) “//api.xxx.com:443/xxx/add
[“query”:protected]=>
string(0) “”
[“fragment”:protected]=>
string(0) “”
}

and this results in 404 because its not matching the route “/xxx/add” but the route “//api.xxx.com:443/xxx/add

If i go without the proxy then it works correctly. Apache log:
158.69.54.232 - - [21/Apr/2020:09:50:51 +0000] “POST /xxx/add HTTP/1.1” 201 4201 “-” “GuzzleHttp/6.5.1 curl/7.58.0 PHP/7.3.16-1+ubuntu18.04.1+deb.sury.org+1”

URI object:
object(Slim\Http\Uri)#49 (9) {
[“scheme”:protected]=>
string(0) “”
[“user”:protected]=>
string(0) “”
[“password”:protected]=>
string(0) “”
[“host”:protected]=>
string(17) “api.xxx.com
[“port”:protected]=>
int(443)
[“basePath”:protected]=>
string(0) “”
[“path”:protected]=>
string(18) “/xxx/add”
[“query”:protected]=>
string(0) “”
[“fragment”:protected]=>
string(0) “”
}

Can someone tell me how i could solve this?

Thank you

The path //api.xxx.com:443/xxx/add is not correct if the request goes through the proxy.

It should be /xxx/add.

You could detect the proxy and fix the path by overwriting the REQUEST_URI

Dirty hack:

$_SERVER['REQUEST_URI'] = str_replace('https://api.xxx.com:443', '', $_SERVER['REQUEST_URI']);

$app->run();

Better solution:

Add a custom middleware, before the routing is done, to manipulate the request object.

Thanx that worked.

I cannot influence the proxy behaviour.

Here is a preg_replace solution if someone else will need it
$_SERVER['REQUEST_URI'] = preg_replace('/^http[s]*\:\/\/.*?(\/.*?)$/', '$1', $_SERVER['REQUEST_URI']);