问题
Without modifying the Symfony code, I want my site to automatically redirect the user to my site's homepage and display a message that the user's session has timed out. Currently, when the time-out occurs the user's browser is automatically redirected to a confusing Symfony error that says:
Cannot redirect to an empty URL. 500 Internal Server Error - InvalidArgumentException
Stack Trace 1. in vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/RedirectResponse.php at line 76 - public function setTargetUrl($url) { if (empty($url)) { throw new \InvalidArgumentException('Cannot redirect to an empty URL.'); } $this->targetUrl = $url;
at RedirectResponse ->setTargetUrl ('') in vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/RedirectResponse.php at line 39
at RedirectResponse ->__construct ('', '302') in vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php at line 82
at Controller ->redirect ('') in src/AppBundle/Controller/BreakinOutBoardController.php at line 5436 +
at XXXXXXXController ->myVideosAction (null)
at call_user_func_array (array(object(XXXXXXXXController), 'myVideosAction'), array(null)) in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php at line 142
at HttpKernel ->handleRaw (object(Request), '1') in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/HttpKernel.php at line 62
at HttpKernel ->handle (object(Request), '1', true) in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/DependencyInjection/ContainerAwareHttpKernel.php at line 67
at ContainerAwareHttpKernel ->handle (object(Request), '1', true) in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php at line 183
at Kernel ->handle (object(Request)) in web/app_dev.php at line 31
Logs - 1 error
INFO - Matched route "app_breakinoutboard_myvideos".
INFO - Populated the TokenStorage with an anonymous Token.
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ValidateRequestListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\LocaleListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\TranslatorListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RouterDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Symfony\Component\HttpKernel\DataCollector\RequestDataCollector::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\HttpCacheListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\SecurityListener::onKernelController".
DEBUG - Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController".
INFO - The "request" service is deprecated and will be removed in 3.0. Add a typehint for Symfony\Component\HttpFoundation\Request to your controller parameters to retrieve the request instead.
INFO - The "request" service is deprecated and will be removed in 3.0. Add a typehint for Symfony\Component\HttpFoundation\Request to your controller parameters to retrieve the request instead.
INFO - The "request" service is deprecated and will be removed in 3.0. Add a typehint for Symfony\Component\HttpFoundation\Request to your controller parameters to retrieve the request instead.
CRITICAL - Uncaught PHP Exception InvalidArgumentException: "Cannot redirect to an empty URL." at /var/www/vhosts/symfony2/vendor/symfony/symfony/src/Symfony/Component/HttpFoundation/RedirectResponse.php line 76
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ValidateRequestListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\FragmentListener::onKernelRequest".
DEBUG - Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\RouterListener::onKernelRequest".
来源:https://stackoverflow.com/questions/56625363/how-do-i-redirect-to-my-sites-homepage-after-my-site-times-out