4

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?

2 Answers 2

4

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);
Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.