Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8284863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:15:57+00:00 2026-06-08T11:15:57+00:00

I’m having a problem completely properly configuring behavior for 500 Internal Server Error pages.

  • 0

I’m having a problem completely properly configuring behavior for 500 Internal Server Error pages.

I have two main use cases:

No headers sent

Fix here is simple, just throw http 500 errors without changing url.

Partial page error

In this case, some html & http headers were already sent to the client. In order to prevent a partly broken page from displaying, I output javascript that causes a redirect completely to an error page url, /error.html . This is to avoid displaying part of a normal page and part of an error page, and make it clear that the resulting html is not optimal even if the section that the error message ends up being displayed in is currently hidden, by moving to a dedicated error page.

Unfortunately, when hitting “back” from the dedicated error page, the original erroring page gets cached, and the javascript redirect is performed again, even if the error has been fixed in the meantime.

For example, if there is an error after headers are sent in index.php, javascript will output that redirects a user to /error.html. Once there, they can return to the homepage (which should be fine), or hit back. When they hit back, they may get a cached page that re-redirects them to error.html.
index.php > error.html (hit back) cached index.php > error.html

What is the ideal way to avoid this situation?

In the code below, I try to add #error hash in the url to redirect only the first time, and on subsequent visits to a broken partial page start a 60 second refresh attempt cycle. Unfortunately, when I set the #error hash and the redirect, then hit back, it goes to index.php, not index.php#error, so the cached infinite loop occurs.

How do I gracefully handle partial-page 500 errors?

Here is the code in my php custom error handler, which causes the above listed behavior:

function showErrorPage() {
    if (headers_sent()) {
    // This is complicated due to the infastructure tending to have already sent headers, ...
    // ...requiring a tuned javascript redirection in many instances.

        // Output the following as html.
        ?>
        <meta http-equiv="Cache-control" content="no-cache, no-store">
        <script type='text/javascript'>
        var currentHash = location.hash;
            // UNFORTUNATELY, HERE THE HASH NEVER SHOWS AS SET!
        if(!currentHash){ // If hash wasn't already set...
            location.hash = '#error';
            location.href = 'error.html'; // Redirect once.
        } else { // Otherwise, the hash was already set, they were redirected once but came back.
            // So just display this page for a time but refresh on a slow schedule.
            setTimeout(function(){
                location.reload(true); // Non-caching refresh.
            }, 60*1000); // Reload after 1 min delay
        }
        </script>
        <?php
    } else {
        // No headers sent, so set the right headers
        header("HTTP/1.1 500 Internal Server Error");
        header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
        header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
    }
    // Regardless, include the visible error output and throw exit with error.
    include(WEB_ROOT.'error.html');
    exit(1);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:15:59+00:00Added an answer on June 8, 2026 at 11:15 am

    I found a useful solution to this, which is as follows:

    Via javascript, hide all the sections of the page and replace them with the error message in a div. Specifically, I wrote out the html directly, styled it hidden, cloned it, removed all the children of the body element, and appendChild’ed the error div to the body, leaving it as the only thing displayed on the page that would otherwise usually have lots of site elements on it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have two tables with like below codes: Table: Accounts id | username |
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.