How to set Apache HTTP Error Code 503 instead of HTTP 500 with PHP Error

Any ideas on replacing the Apache HTTP 500 (Internal Server Error) error with HTTP 503 (Service Unavailable) with a PHP error after the PHP error display is turned off? This is a much better way to tell spiders to return to the site soon ...

PS it would be great if it was possible to add Retry-After to the 50x error codes, if possible ...

amuses / Marcin

+1
source share
2 answers

I assume that you are referring to PHP new (starting with 5.2.4) the default behavior is throwing 500 if an error occurs and no other output is made.

AFAIK, this behavior is hard-coded; you cannot change this without changing PHP itself.

The easiest way is to set up a custom error handler and get 503 for you:

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

I wonder if you can do something like Apache

 Redirect 503 /error/500 /maintenance.html 

on the

 ErrorDocument 500 /error/500 

directive?

0
source

Source: https://habr.com/ru/post/1343841/


All Articles