I am trying to modify the Url entering the Symfony kernel but leaving all the others unchanged. Have tried usinh Request::create but that method replaces all other variables in the request.
How can this be done?
I found this via search... i dont know if this was working on symfony 2, but on symfony 5, this would replace the initial array having all server params, with the only one param 'REQUEST_URI'.
The alternative (Symfony 5) to keep all other keys:
$serverBag = $request->server;
$requestUri = $serverBag->get('REQUEST_URI');
$serverBag->set('REQUEST_URI',str_replace('/oldUrl', '/newUrl', $requestUri));
$request = $request->duplicate(null, null, null, null, null, $serverBag->all(), null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With