Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modify Url in Request Object in Symfony2

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?

like image 647
Stanley Ngumo Avatar asked Oct 22 '25 14:10

Stanley Ngumo


1 Answers

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);
like image 146
adaz Avatar answered Oct 25 '25 05:10

adaz