I have a symfony application that when running in the production server doesn't handle correctly the 404 errors, this is the error I get in the error log:
Fatal error: Uncaught exception 'Symfony\Component\Routing\Exception\ResourceNotFoundException' in /var/www/site/releases/20160119210649/app/cache/prod/appProdUrlMatcher.php:7768
Stack trace:
0 /var/www/site/releases/20160119210649/app/cache/prod/classes.php(1419): appProdUrlMatcher->match('/daf')
1 /var/www/site/releases/20160119210649/app/cache/prod/classes.php(8339): Symfony\Component\Routing\Matcher\UrlMatcher->matchRequest(Object(Symfony\Component\HttpFoundation\Request))
2 /var/www/site/releases/20160119210649/app/cache/prod/classes.php(2483): JMS\I18nRoutingBundle\Router\I18nRouter->matchRequest(Object(Symfony\Component\HttpFoundation\Request))
3 [internal function]: Symfony\Component\HttpKernel\EventListener\RouterListener->onKernelRequest(Object(Symfony\Component\HttpKernel\Event\GetResponseEvent), 'kernel.request', Object(Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher))
4 /var/www/site/releases/20160119210649/app/cache/prod/classes.php(2264): call_user_func(Array, O in /var/www/site/releases/20160119210649/app/cache/prod/classes.php on line 5336
I have my 404 error customized in /app/Resources/TwigBundle/views/Exception/error404.html.twig I've cleared the cached and even restarted php and nginx.
I had the exact same error and found the solution after long research. I have a language switch in my footer and these routes were generated with the current route and the _locale
parameter.
{{ path(app.request.get('_route'), app.request.get('_route_params')|merge({'_locale': 'de'})) }}
But on a 404 error there is no route. That ended in this 500 error. Now I wrapped this link into an if statement like this and it works:
<li>
<a href="{% if app.request.get('_route') != "" and app.request.get('_route_params') is not null %}
{{ path(app.request.get('_route'), app.request.get('_route_params')|merge({'_locale': 'en'})) }}
{% else %}
{{ path("homepage", {'_locale': 'en'}) }}
{% endif %}">
English
</a>
</li>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.