4

After reading some tutorials, I have created an error file, that should be displayed instead of 500 server error. I have added it to domain's root and added the following line to the bottom of .htaccess:

ErrorDocument 500 /error.html

Now the question is, how can I test it on a live site and make sure that the error page appears, when site really crashes?

Any suggestions are much appreciated.

5 Answers 5

2

I created a folder called http500 in the www root

I put a .htaccess file into that folder with the following:

Redirect 500 /http500

I then opened it http://example.com/http500

You can try out different error pages

Redirect 501 /http500

or

Redirect 502 /http500

or

Redirect 503 /http500

It did not require any server restart, the change applied immediately.

Sources:
https://stackoverflow.com/a/8687536/534883
https://bibwild.wordpress.com/2013/06/05/how-to-make-apache-fake-a-500-http-response/

1
  • "I created a folder ..." - You don't need to actually create the folder, if you are testing the main .htaccess in the root. eg. Redirect 503 /http503.
    – MrWhite
    Jan 25, 2019 at 0:36
1

make sure that the error page appears, when site really crashes?

It depends what you mean by "when the site really crashes". A "500 Internal Server Error" is such a generic error... if the server is unable to process the request for whatever reason and there is no other suitable response then it defaults to a 500 error response.

The "problem" here is that for the majority of uncontrolled 500 errors, defining the 500 ErrorDocument late in .htaccess is simply too late to have any effect.

You can trap more 500 error responses if the 500 ErrorDocument is defined earlier in the server config or <VirtualHost> container - this is where it should be defined. But even then, depending on the severity of the error, the custom ErrorDocument may still not be called.

You can "artificially" trigger a 500 response as @TimoHuovinen suggests and this would trigger your custom 500 ErrorDocument, however, whether this triggers when your "site really crashes" is another matter entirely.

0

Create a new directory end enter a non functional .htaccess (e.gg, with a Syntax Error or similar) file in that directory. Then access that dir with a browser.

2
  • Sorry, I did not understand it. Should I create a new category in the root of the domain and then create .htaccess in there ( what is 'non functional'? )?
    – Domas
    Feb 19, 2016 at 12:01
  • This won't trigger a custom 500 ErrorDocument that is itself defined in .htaccess.
    – MrWhite
    Oct 18, 2020 at 17:55
0

Have a look at this:

How to trigger 500 Internal Server Error in PHP?

https://stackoverflow.com/a/8687536/534883

1
  • Triggering a 500 error response in PHP won't result in an Apache defined 500 ErrorDocument being called. In the same way a 404 response from PHP won't trigger the 404 Apache response.
    – MrWhite
    Oct 18, 2020 at 17:58
0

I know this is an old question, but I was currently facing the same problem, so I thought I'd share my (simple) solution without creating subfolders

Since

Redirect Err# /path

leads me to unstartable server, I found a better solution for me.

If you use custom error documents like:

ErrorDocument 400 /res/err/400.php
ErrorDocument 401 /res/err/401.php
ErrorDocument 403 /res/err/403.php
ErrorDocument 404 /res/err/404.php
ErrorDocument 500 /res/err/500.php

You can simply add the following to your .htaccess (or your VirtualHost or Server config)

RewriteEngine on

# To test our custom error pages
RewriteRule ^/err400(.*)$ https://your.servername.dev/res/err [NC,R=400,L]
RewriteRule ^/err401(.*)$ https://your.servername.dev/res/err [NC,R=401,L]
RewriteRule ^/err403(.*)$ https://your.servername.dev/res/err [NC,R=403,L]
RewriteRule ^/err404(.*)$ https://your.servername.dev/res/err [NC,R=404,L]
RewriteRule ^/err500(.*)$ https://your.servername.dev/res/err [NC,R=500,L]

Now you can test your error pages by typing the url in your browser, like that:

http://your.server.dev/err400

or:

https://your.servername.dev/err403

Hope that helps B)

Addendum:

Ensure mod_rewrite is enabled

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .