丢失图像时出现 symfony 500 错误
我们注意到当我们的网站中缺少图像时会出现许多 500 错误(出现这种情况的原因有多种) - symfony 将首先尝试在通常的“uploads/custom/myasset.jpg”文件夹中找到该资源,如果它存在找不到资产,那么它将通过 symfony 来尝试找到匹配的路线,正是这种“通过”symfony 导致了轻微的性能问题,我想知道是否有其他人遇到过这个问题以及他们是如何解决的。
我尝试过 mod_rewrite 规则,但我的正则表达式知识很糟糕!
干杯!
We have noticed a number of 500 errors when an image is missing from our site (this happens for various reasons) - symfony will try to locate the asset first of all in the usual 'uploads/custom/myasset.jpg' folder and if it cannot find the asset then it will look through symfony to try find a matching route, its this 'going through' symfony that is causing a slight performance issue and I was wondering if anyone else has encountered this issue and how they resolved it.
I have tried with a mod_rewrite rule but my regexp knowledge sucks!
Cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以添加 RewriteCond 以从 RewriteRule 中排除某个目录。
例如:
将从 symfony 前端控制器的默认重写规则中排除任何以“/images/”开头的请求。您可以根据需要在 RewriteRule 之前添加任意数量的 RewriteCond,或者您可以修改正则表达式以考虑不同的情况,例如:
但是,您的问题表明仍然存在另一个问题,因为 symfony 应该在无法路由时抛出 404 期望请求,这会产生 HTTP 404 响应。它绝对不会导致 HTTP 500 响应。也许有故障的 404 控制器正在抛出异常。您应该进一步调查错误 500 的原因。
You could add a RewriteCond to exclude a certain directory from the RewriteRule.
For example:
Would exclude any request starting with "/images/" from the default rewrite rule for the symfony front controller. You can add as many RewriteCond before the RewriteRule as you want, or you could modify the regexp to account for different cases, like:
However, your question suggests there is another problem still, as symfony should be throwing 404 expections when it cannot route a request, which results in a HTTP 404 response. It definitely would not result in a HTTP 500 response. Maybe a faulty 404 controller is throwing an exception. You should further investigate the reason of the the error 500.