Redirect after saving an entry
The redirect url always needs to be hashed:

https://docs.craftcms.com/v3/dev/functions.html#redirectinput

In Twig you can use {{ redirectInput(url) }} which is a shortcut of

&lt;input type="hidden" name="redirect" value="{{ url|hash }}"&gt;


But if you need the same in a PHP code you can use

Craft::$app-&gt;getSecurity()-&gt;hashData($url)


based on the code how the Twig filter defined in craftcms/cms/src/web/twig/Extension.php.