如何显示 404 错误页面而不是 Symfony4 中的错误

How to display the 404 error page instead bugs in Symfony4

这是我的页面:error404.html.twig 作为文档 Example 404 Error Template

{# templates/bundles/TwigBundle/Exception/error404.html.twig #} 
{% extends 'base.html.twig' %}
{% block body %}
<h1>Page not found</h1>
        <p>
            The requested page couldn't be located. Checkout for any URL
            misspelling or <a href="{{ path('homepage') }}">return to the homepage</a>.
        </p>

{% endblock %}

这是我的页面config/routes/dev/twig.yaml

# config/routes/dev/twig.yaml
_errors:
    resource: '@TwigBundle/Resources/config/routing/errors.xml'
    prefix:   /_error

这是我的页面config/packages/twig.yaml

# config/packages/twig.yaml
twig:
    exception_controller: App\Controller\ExceptionController::showException

我应该怎么做才能让它发挥作用?

错误是:

services.yaml :

如果您处于调试模式,而不是 404 页面,您会得到 NotFoundHttpException 那么一切都很好,因为这是记录在案的所需行为,如下所述:https://symfony.com/doc/current/controller/error_pages.html

In the development environment, Symfony catches all the exceptions and displays a special exception page

要绕过这个并真正看到您的自定义 404 页面,您需要通过特殊路径访问模板:http://localhost/index.php/_error/404