title: Redirect with Event Listener for all "No route found 404 Not Found - NotFoundHttpException"
body: <p>How can I trigger redirect to a specific router in event listener?</p>
  
  <p>There are many examples but I couldn't find one for "GetResponseForExceptionEvent". For exampe, when I pass <code>@roter</code> as an argument <code>$this-&gt;router....</code> doesn't seem to be working so on.</p>
  
  <p>I checked these but I probably missed something:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/15983082/show-a-specific-route-instead-of-error-page-404-symfony2">Show a specific route instead of error page (404) - Symfony2</a></li>
  <li><a href="https://stackoverflow.com/questions/13564466/symfony2-hook-into-notfoundhttpexception-for-redirection">symfony2: hook into NotFoundHttpException for redirection</a></li>
  <li><a href="https://stackoverflow.com/questions/12916439/symfony2-redirect-for-event-listener">Symfony2 redirect for event listener?</a></li>
  <li><a href="https://stackoverflow.com/questions/11505287/symfony2-getting-route-in-page-load-event-listener/11506088#11506088">Symfony2: Getting Route in Page Load Event Listener</a></li>
  <li><a href="https://stackoverflow.com/questions/10487557/redirect-if-the-user-is-logged-in">Redirect if the user is logged in</a></li>
  </ul>
  
  <p><strong>service.yml</strong></p>
  
  <pre><code>services:
      kernel.listener.kernel_request:
          class: Booking\AdminBundle\EventListener\ErrorRedirect
          tags:
              - { name: kernel.event_listener, event: kernel.exception, method: onKernelException }
  </code></pre>
  
  <p><strong>Event listener:</strong></p>
  
  <pre><code>namespace Booking\AdminBundle\EventListener;
  
  use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
  use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  
  class ErrorRedirect
  {
      public function onKernelException(GetResponseForExceptionEvent $event)
      {
          $exception = $event-&gt;getException();
  
          if ($exception instanceof NotFoundHttpException) {
              // redirect to '/' router or '/error'
              //$event-&gt;setResponse(...........);
          }
      }
  } 
  </code></pre>