How to set Apache HTTP 503 error code instead of HTTP 500 on PHP error

吃可爱长大的小学妹 提交于 2019-12-23 03:08:13

问题


any ideas how to replace Apache HTTP 500 (Internal Server Error) error by HTTP 503 (Service Unavailable) on PHP error once PHP error displaying is off? This is much better option to inform spiders to back to the site soon...

P.S. would be great to be able to append Retry-After to the 50x error codes if possible...

cheers, /Marcin


回答1:


I assume you are referring to PHP's new (since 5.2.4) default behaviour of throwing a 500 if an error occurs, and no other output is being made.

AFAIK, that behaviour is hard-coded, you won't be able to change that without changing PHP itself.

The easiest way may be setting up a custom error handler, and having that throw a 503 for you:

header("HTTP/1.1 503 Service Unavailable");
echo "--- error message here -----";
die();



回答2:


I wonder if you could do something like an Apache

Redirect 503 /error/500 /maintenance.html 

on an

ErrorDocument 500 /error/500 

directive?



来源:https://stackoverflow.com/questions/5343677/how-to-set-apache-http-503-error-code-instead-of-http-500-on-php-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!