简体   繁体   English

IIS7.5上PHP网站的自定义500页

[英]Custom 500 page for PHP site on IIS7.5

I have a PHP (5.3) site running on a Windows 2008 R2 server (IIS7.5) & I'm trying to get a custom 500 page showing. 我有一个在Windows 2008 R2服务器(IIS7.5)上运行的PHP(5.3)站点,并且试图显示一个自定义的500页。

I've setup a test page, which generates a Fatal error - Call to undefined function functiondoesnotexist() in... 我已经设置了一个测试页面,该页面会生成致命错误-调用未定义函数functiondoesnotexist()在...

If I set error handling in the script to: 如果我在脚本中将错误处理设置为:

ini_set('display_errors', 1);
error_reporting(E_ALL);)

I do get to see the error on the page, BUT the page returns a 200 code. 我确实看到了页面上的错误,但是页面返回了200个代码。

If I turn off the error reporting, I just get a blank page (no source code at all), but the status is 500 如果我关闭错误报告,我只会得到一个空白页面(根本没有源代码),但是状态是500

However, it doesn't show the custome error page (500.php) - which is working when loaded directly. 但是,它没有显示客户错误页面(500.php)-直接加载时该页面有效。

Does anyone know what I'm missing? 有人知道我在想什么吗? Thanks 谢谢

To show a custom static file as a 500 error in a PHP site under IIS, after configuring the custom page through the IIS UI, you need to edit the web.config file and locate the httpErrors section. 要在IIS下的PHP站点中将自定义静态文件显示为500错误,请通过IIS UI配置自定义页面后,需要编辑web.config文件并找到httpErrors部分。 In this configuration node you must set the existingResponse property to "Replace" so that fastCGI uses the default IIS response instead of the fastCGI response that PHP uses. 在此配置节点中,必须将existingResponse属性设置为"Replace"以便fastCGI使用默认的IIS响应而不是PHP使用的fastCGI响应。

Your web.config file section should look something like this: 您的web.config文件部分应如下所示:

<httpErrors existingResponse="Replace"> <remove statusCode="500" subStatusCode="-1" /> <error statusCode="500" prefixLanguageFilePath="" path="MyCustom500Errorpage.html" responseMode="File" /> </httpErrors>

Notice the property in the root node and the responseMode attribute set to File in the error node. 请注意,根节点中的属性以及error节点中的responseMode属性设置为File

The file is located at the root folder. 该文件位于根文件夹中。 If you have any images, scripts or .css files used in it, make sure you're using paths related to the root folder (eg: "/Images/MyLogo.png" etc...). 如果其中使用了任何图像,脚本或.css文件,请确保使用与根文件夹相关的路径(例如: "/Images/MyLogo.png"等)。

HTH HTH

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

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