2

I want to display 500 error information to the end-user

For instance, it should happen when I request a page https://website.net/crashedPage


There are 2 options:

Option 1

Perform redirect to the page https://website.net/Error-500

Sequence of codes: 302 => 500


Option 2

Return response with 500 error code directly and don't change URL https://website.net/crashedPage

Sequence of codes: 500


Question

Whether the first option is a bad practice and why?

2

It is always best to show errors at the original URL rather than redirecting.

For SEO, Google knows how to deal with 500 errors. It will give the page some grace time (probably 24 hours) and if the error doesn't go away it will stop indexing it.

Google will probably treat a redirect to a 500 error the same way, but there is no guarantee. In general, Google does not index redirecting URLs. The danger would be that Google would immediately stop indexing the original URL because it sees a redirect, rather than giving it the customary grace period for a 500 error.

For users, it is also better to show the error at the original URL. Changing the URL is not user friendly. It makes it harder for users to see what happened. They won't be able to note the original URL when they email you or talk to your support. They won't be able to refresh the page to see if the error has gone away.

Most web servers come configured by default to show the error at the original URL rather than redirecting. Unfortunately, it is easy to mis-configure Apache to redirect when specifying a custom error page. Consider this directive:

ErrorDocument 500 https://example.com/errors/500.html

That will cause Apache to redirect to the error page rather than serve up the error directly at the original URL. To fix it, simply make the URL relative so that Apache can show that error page with the error status at the original URL:

ErrorDocument 500 /errors/500.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.