title: Symfony : Redirect errors 403, 500, ... to the 404 page
body: <p>I followed the instructions <a href="https://symfony.com/doc/current/controller/error_pages.html" rel="nofollow">here</a> and I did a custom error.html.twig (The 3rd case). I did a custom controller too.</p>
  
  <p>I have 2 problems:</p>
  
  <p><strong>1st problem</strong>
  Where do I have to put my custom controller? I don't understand the doc for this: <a href="https://symfony.com/doc/current/controller/error_pages.html#overriding-the-default-exceptioncontroller" rel="nofollow">https://symfony.com/doc/current/controller/error_pages.html#overriding-the-default-exceptioncontroller</a></p>
  
  <p><strong>2nd problem</strong>
  I'm trying to redirect 403, 500, ... errors to this page. Actually, when you try to access a folder you have "Access forbidden".</p>
  
  <p>I tried to add this in the .htaccess : <code>ErrorDocument 403 http://www.xxx.fr/</code> but I don't know what the URL is of the 404 page.</p>
  
  <h1>EDIT</h1>
  
  <p>Ok I understood where to put my controller but I get an error.</p>
  
  <p>This is my <strong>ExceptionController.php</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>namespace Symfony\Bundle\TwigBundle\Controller;
  
  use Symfony\Component\Debug\Exception\FlattenException;
  use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
  use Symfony\Component\HttpFoundation\Request;
  use Symfony\Component\HttpFoundation\Response;
  
  
  class ExceptionController
  {
      public function showAction()
      {
          $dir = $this-&gt;get('kernel')-&gt;getRootDir() . '/../web/images/theme/404/';
          $dh  = opendir($dir);
          $errorFiles = array();
          while (false !== ($filename = readdir($dh)))
              if ($filename != '.' &amp;&amp; $filename != '..' &amp;&amp; $filename[0] != '.')
                  $errorFiles[] = $filename;
  
          shuffle($errorFiles);
  
          return $this-&gt;render('errors/show.html.twig', [
                      'gifs' =&gt; $errorFiles
          ]);
      }
  }
  </code></pre>
  
  <p><strong>The error</strong></p>
  
  <blockquote>
    <p>Whoops, looks like something went wrong.</p>
    
    <p>1/1 UndefinedMethodException in ExceptionController.php line 30:
    Attempted to call an undefined method named "get" of class
    "Symfony\Bundle\TwigBundle\Controller\ExceptionController". in
    ExceptionController.php line 30</p>
  </blockquote>
  
  <p>This controller worked fine with a classic view.</p>