Symfony2 error 500 instead of 404 at production

前端 未结 11 1199
野性不改
野性不改 2020-12-06 04:49

In my Symfony2 project I\'m getting at development mode correct 404 Exception screen. But I\'m getting blank screen with HTTP status code 500 instead of 404 at production mo

相关标签:
11条回答
  • 2020-12-06 04:50

    In my case it was use of {% stylesheets %} tag in a 404 template, while TwigBundle was not included in the Assetic config.

    Check your app/logs/prod.log, it should have an answer.

    0 讨论(0)
  • 2020-12-06 04:52

    Here is how I redirect all non existent routes to root path. Put this route entry on the very bottom of your routing configuration. All existent route MUST be on top of it!

    anything:
        path:     /{path}
        defaults:
            _controller: FrameworkBundle:Redirect:urlRedirect
            path: /
            permanent: true
        requirements:
            path: ".+"
    

    reference:
    http://symfony.com/doc/current/cookbook/routing/slash_in_parameter.html
    http://symfony.com/doc/current/cookbook/routing/redirect_in_config.html

    0 讨论(0)
  • 2020-12-06 04:54

    I encounteres that Symofny 3 throws an 500 error in production when you do not use

    $this->createNotFoundException()
    

    in your Controller.

    throw Exception('message', 404)
    

    works on dev-enviroment, but not on production.

    0 讨论(0)
  • 2020-12-06 05:07

    ResourceNotFoundException is what the router throw when no route match the current request.

    This can be a cache issue (80% of the time, it's the cache. Try rm -rf app/cache/* on your pre-production server). As the issue does not appear locally... (you tried the "prod" env locally right?).

    You should also try to remove everything from your app/Resources/TwigBundle/views/Exception/error404.html.twig (is that the filename you use?) except simple HTML, to check if it's not a twig issue.

    0 讨论(0)
  • 2020-12-06 05:08

    Another option is that you're trying to access the security token in the security context when no token is available.

    0 讨论(0)
  • 2020-12-06 05:09

    Symfony\Component\Routing\Exception\ResourceNotFoundException means undefined route name. It looks like you've got somewhere in your error template {{ path('wrong_route') }}.

    0 讨论(0)
提交回复
热议问题