简体   繁体   English

将所有404错误代码处理到Symfony中的自定义页面

[英]Handle all 404 error code to custom page in Symfony

I created a custom Controller to handle all different routes, so if I enter an invalid route I raise a NotFoundHttpException to my custom error 404 page in app/TwigBundle/views/Exception/error404.html.twig . 我创建了一个自定义控制器来处理所有不同的路由,因此,如果输入无效的路由,则会在app/TwigBundle/views/Exception/error404.html.twig向我的自定义错误404页面引发NotFoundHttpException

It is working fine with all routes except with routes that end in .php where I am getting the default error page. 它与所有路由都可以正常工作,但以.php结尾的路由除外,在该路由中我得到默认错误页面。 Any suggestion? 有什么建议吗?

It seems that you may actually have an error in your webserver configuration. 看来您的网络服务器配置实际上可能有错误。

The webserver (eg Apache/Nginx) should rewrite everything that is not a file ( RewriteCond %{REQUEST_FILENAME} !-f ) to app.php ( RewriteRule ^(.*)$ app.php [QSA,L] ) 网络服务器(例如Apache / Nginx)应将不是文件的所有内容( RewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ app.php [QSA,L]为app.php( RewriteRule ^(.*)$ app.php [QSA,L]

If you are being shown the default 404 page, I would guess there is something wrong with the webserver config. 如果显示默认的404页面,则可能是Web服务器配置有问题。

Could you post/describe your current webserver config (Sanitized is fine, just need to see rewrite rules)? 您能否发布/描述您当前的Web服务器配置(已清理就可以了,只需要查看重写规则即可)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM