Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 393
Vivien Avatar asked May 18 '12 11:05

Vivien


People also ask

Where can I find 404s?

Google Search Console: You will find a list of all 404 pages by logging into your Google search console account and going to Diagnostics > Crawl Errors. After you click on “Not Found”, a list of all the urls that result in a 404 error will appear.

What do you do with 404s?

404s should not always be redirected. 404s should not be redirected globally to the home page. 404s should only be redirected to a category or parent page if that's the most relevant user experience available. It's okay to serve a 404 when the page doesn't exist anymore (crazy, I know).

Why do 404s happen?

404 errors occur when a user or search crawler tries to access a page that does not appear to exist on a domain. 404 errors happen when: A page is deleted from your website without a 301 redirect. Someone makes a mistake typing the page URL into their browser's address bar.


1 Answers

To display error pages, in web/app_dev.php change second parameter to false

$kernel = new AppKernel('dev', false);

After testing what you need, change it back.


UPDATE

Thanks @user2019515 for pointing that out - now (2.3 and up) there's a link to WebfactoryExeptionsBundle in Symfony docs and the method I wrote above should not be used.

like image 76
Karmalakas Avatar answered Sep 28 '22 12:09

Karmalakas