How to load a different Page if a page can not be found (404)

I would like to find out how to Load a Local page if the the page I requested server in not online

If I requested:

If Not found or a error 404 then:
load a local Page:

Who is Participating?
venkateshwarrConnect With a Mentor Commented:
It depends on server....
for example in IIS.

The page location is usually,

you can specify the 404 file in the server settings... and modify accordingly
eeBlueShadowConnect With a Mentor Commented:
The easiest way to do this, if your server admin has allowed it, is by using a .htaccess file (assuming the server is running Apache)

create a file called .htaccess containing the following line

ErrorDocument 404 /path/from/root/to/notfound.htm

or add the line to the bottom of an existing .htaccess file if there's already one in the directory. If you get a Server Error 500 when you try to view any page in that folder, then the server is set up not to let you do things like setting individual error pages
COBOLdinosaurConnect With a Mentor Commented:
Client side only for both a missing page and server down you can use XMLHTTP to allow you page to stay in control:

<script language='JavaScript'>
function testIt(url)
   if (document.all)
      // IE version
      try {
      var xml = new ActiveXObject("Microsoft.XMLHTTP");
      xml.Open( "GET", url, false );
      catch (e) {
      var xml = new ActiveXObject("MSXML2.XMLHTTP.4.0");
      xml.Open( "GET", url, false );
      // Mozilla/Netscrap 6+ version
            var xml=new XMLHttpRequest();
Now you can test the status. You can find the HTTP status codes here:
if (http.status == 404 || http.status == 500) {
// Do something because the page cannot be accessed
if (http.status == 200) {
// Do something because the page does exist
// of course you could also used what has already been retrieved
// with document.documenElement.innerHTML=xml.responseText

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.