-
Notifications
You must be signed in to change notification settings - Fork 27
Create a 404 Error page for NotFoundHttpException #1
Comments
Should this not be handled by the application rather than the bundle? Although an interesting approach for this would be to query the routes and find those which are closest to the given URL, something like "did you mean .....?". |
It is a good way not to show an Exception or the Error itself in production. It is a better way to show a user friendly page with some information to, which should help the user to navigate to other content. And the only error that should appear, should be a route-not-found-error caused by older links or (in most cases of my customers) old bookmarks. In this case the user should get informations like:
To design this page is a task of the application, but to show it could be a task of the SeoBundle. The 404 is not for the user, its for google (or others, are there others? g). By this google knows it too, that the route does not exist anymore. |
I think a good way would be to add a listener on that exception. or is there a Kernel event or better a event from our own routing bundle? |
Adding an exception listener is pretty easy in Symfony, this is an example from some some code I work on: $container->register('yprox.exception.listener', 'Ylly\CmsBundle\Exception\ExceptionListener')
->addArgument(new Reference('templating'))
->addTag('kernel.event_listener', array('event' => 'kernel.exception', 'method' => 'onKernelException')); So you could add that listener (giving it a high priority) and if the Exception is of the type thrown by the ChainRouter, or indeed if it is any public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $this->buildException($event);
$event->setResponse(new Response($this->getTemplating()->render('CmsBundle:AdminException:exception.html.twig', array(
'exception' => $event->getException(),
)), 404));
return true
} |
right, thanks, I just red the symfony docs about that theme :-). One word to the configs. There a two ways in my mind. One with one error page:
Or a way with several contexts to handle different errors:
by setting the listen_to property i can filter the Exception and handle different behaviors. |
i think the twig bundle allows all you usually need: http://symfony.com/doc/current/cookbook/controller/error_pages.html - you can already overwrite the template per error status. things that go further are very specific anyways. it makes sense to explain the importance of setting up good error pages in the doc chapter, and we can also link to the exception listener doc of symfony for people that need to go further. but adding our own error handling makes little sense imho. |
You mean, just a part in the docs, instead of an own handling? But there is an other important thing, and that is SEO:
I red a realy good article for UX in the magazine "der web designer" Oct/12 "Benutzerfreundliche Fehlerseiten". Sounds like a design article but is a SEO article too. Cause ErrorPages are show on search engine previews too. And if there is just a blank page or the servers default 404 page it can very bad if the content is a product in a webshop for example. (sorry if am to enthusiastic in discussion) |
okay, if we manage to do a semantical error page that proposes options (maybe looking for path fragments, urls with other locales, search with url segments) that would indeed have added value. but i would postpone such things to a 1.1 version (and it will remain very specific as people will want to tune this a lot to their specific use case) |
Yes i thing the SeoBundle itself is a thing for after 1.1, or? |
there is no rush. but i think getting something simple but clean and |
solved by #192 |
Instead of the Exception i would be good for SEO that the user see an error-page, with information for navigating the content or hints for equal content.
The text was updated successfully, but these errors were encountered: