Accepted answer

Continued to do some research and found that it can be done using the duplicate method. Example:

$new_url = $request->duplicate(null, null, null, null, null, array('REQUEST_URI' => $old_url, null));

Hope this is helpful


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);

Related Query

More Query from same tag