捕获所有错误并重定向到php页面 [英] catching all errors and redirecting to page with php

查看:72
本文介绍了捕获所有错误并重定向到php页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法普遍地告诉php重定向到某个页面上任何致命的错误?

Is there say way to universally tell php to redirect to a certain page on any fatal errors?

说我有一个网站有很多不同的文件,我想隐藏问题(同时仍然记录它们),并将用户发送到同一个错误页面,无论出现什么错误或是哪些页面。

Say i have a site with many different files, and i want to hide problems (while still logging them) and send the user to the same error page, no matter what the error is or what page they are on.

只是假装为了争论,我不想看到错误,这些页面被不断的编辑和更新由机器人谁导致错误每23或51页编辑。

Lets just pretend for sake of argument that i dont want to see the errors, and the pages are being continuously edited and updated by robots who cause errors every 23rd or 51st page edit.

我正在寻找可能涉及php.ini文件或htaccess的东西,我可以在网站上做一些。

Im looking for something that perhaps involves the php.ini file, or htaccess, something that i can do site wide.

推荐答案

您可以使用'ErrorDocument'指令更改Apache中的默认500错误页面:

You can change the default 500 error page in Apache with the 'ErrorDocument' directive:

ErrorDocument 500 /500.html

这将将500内部服务器错误重定向到500.html。您也可以使用PHP页面并发送引用页面。

This redirects a 500 Internal Server error to 500.html. You can also use a PHP page there and mail the referring page.

要捕获错误,您可以将其记录到error.log文件。在您的php.ini文件中使用以下两个指令:

To catch the errors you can log those to an error.log file. Use the following two directives in your php.ini file:

error_log = /var/log/httpd/error_php  
log_errors = On  

不要忘记重新启动Apache。

Don't forget to restart Apache.

这篇关于捕获所有错误并重定向到php页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆