0

I would like to ask your assistance on how I can possibly redirect properly the Error 500 Internal Server page only to a custom page and otherwise our webpage will be accessible. Currently, I have a code but even our system is accessible it's still redirecting to a custom page

My background.js

function redirect(requestDetails) {
  console.log("Redirecting: " + requestDetails.url);
  return {
    redirectUrl: "https://cmms.domainhosting.com/cmms/ma.html"
  };
}

chrome.webRequest.onBeforeRequest.addListener(
  redirect,
  {urls:["http://cmms/may/ui"]},
  ["blocking"]
);

My manifest

{

  "description": "Intercept and Redirect Error 500 Page",
  "manifest_version": 2,
  "name": "Web Request",
  "version": "12.8.2018",
  "icons": {
        "24": "icons/24.png",
        "48": "icons/48.png",
        "128": "icons/128.png"
  },
  "browser_action": {
        "default_icon": "icons/48.png"
  },

  "permissions": [
    "webRequest",
    "webRequestBlocking",
    "http://cmms/may/"
  ],

  "background": {
    "scripts": ["background.js"]
  }

}

I have read that onBeforeRedirect can achieve my needs but I don't have any idea how to code it.

Thanks!

1 Answers1

0

As stated in this link, custom pages for 500 only work if the cause of the 500 can be handled by Apache to display the page.

Say for instance you made a syntax error in your .htaccess page or in your apache config file, it's going to throw a 500 server error but because Apache is down, it can't serve anything including that custom page, so you get the browsers default page. Also depending on how you have your PHP error reporting setting you won't get 500 custom page either. There is a lot more to this and customizing 500 page is almost useless cause most people won't ever see that. You will know before they will because it's a 500 is typically configuration issue, like a syntax error in your code.

Also from this page,

Although most error messages can be overridden, there are certain circumstances where the internal messages are used regardless of the setting of ErrorDocument. In particular, if a malformed request is detected, normal request processing will be immediately halted and the internal error message returned. This is necessary to guard against security problems caused by bad requests.

You may check this thread for additional reference: How to create custom 401, 403 and 500 error pages?

abielita
  • 13,147
  • 2
  • 17
  • 59
  • Thanks for detailed response though it was too complicated, I have fixed my issue already by creating an Chromium Based extension thru webRequest onHeadersReceived. I will share my code later – HOKSA Prod Dashboard Aug 16 '18 at 22:57