0
votes

How can I show a custom page when a 500 Internal Server Error occurs?

I created a page called '500.php'.
Then added the following line to my '.htaccess' file to handle the error:

ErrorDocument 500 /500.php

And the following line to test/trigger a 500 error:

e

But the default 500 page shows up - not my custom one.

I tried editing the first line to this (whole URL):

ErrorDocument 500 http://danispringer.com/500.php

But then I get the "Too many redirects" error.

How can I do this?

1
You don't need to use a RewriteRule if you're going to use ErrorDocument.Funk Forty Niner
ErrorDocument 500 /500.php is enough.Funk Forty Niner
there's no need to "trigger" an error per se. If and when a script errors out as a server error. Apache takes over and looks for the ErrorDocument 500 automatically.Funk Forty Niner
that is exactly it ;-) the only way to test it would be with a conditional statement of something that doesn't work, and with something that does. All Apache directives that can be caught, will be triggered and handled respectively of the handle request.Funk Forty Niner
set your server settings to not show errors but log them and then deliberately leave out a missing semi-colon somewhere; that will trigger a server error. Best I can add to all this and we've just triggered the "Please avoid extended discussions in comments. Would you like to automatically move this discussion to chat?". The question could get closed and/or trigger a "too chatty, moved to chat...." by a mod. You'll need to let all that sink in and try something ;-) cheers. I believe I answered it somewhat.Funk Forty Niner

1 Answers

0
votes

First of all I would not use a php file if not absolutely necessary, because if you have a problem with php that you also can't show your 500.php page.

I would create a folder /errors and put all my error files in this e.g.:

/errors/404.html
/errors/403.html
/errors/500.html

Now If you looking for a solution to test a 500 error then just create a folder (e.g. test500folder) and put an invalid .htaccess file in this folder /test500folder/.htaccess:

abc

Now you can test you 500 error if you open example.com/test500folder/

but remove: RewriteRule ^ - [R=500] and everything else but use only

ErrorDocument 403 /errors/403.html
ErrorDocument 404 /errors/404.html
ErrorDocument 500 /errors/500.html

in your main htaccess file to test.

Edit:

So I assume that you, or your provider, have configured a location for all you ErrorDocumentes, but these files are deleted now. You have to replace exact this files or configure some other in your providers back end, if possible.