Search code examples
symfonydevelopment-environment

How to display the 404 error page in Symfony2 dev environment


I want to work on the 404 page from the dev environment. I customize 404 using this file : app/Resources/TwigBundle/views/Exception/error.html.twig

This prod url work correctly : mysite.com/404

But this one mysite.com/app_dev.php/404 throw a NotFoundHttpException and give me the dev debug page.

Is it possible to display the error page instead of debug page ?

UPDATE:

The official documentation has now a chapter about that : Testing Error Pages during Development


Solution

  • As of Symfony2.6 in dev environment, you can use the following route:

    /_error/404.html
    

    Where 404 is the error code to test and html the format of the request. To be able to use this features, make sure you have the following entry in your routing_dev.yml file:

    # app/config/routing_dev.yml
    _errors:
        resource: "@TwigBundle/Resources/config/routing/errors.xml"
        prefix:   /_error