Solved

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

Posted on 2004-04-23
5
173 Views
Last Modified: 2010-04-09
I would like to find out how to Load a Local page if the the page I requested server in not online

Example:
If I requested:

http://myxp.sytes.net/private/private.htm

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

0
Comment
Question by:realredneck
5 Comments
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 43 total points
ID: 10902074
It depends on server....
for example in IIS.

The page location is usually,
C:\WINDOWS\help\iisHelp\common\400.htm

you can specify the 404 file in the server settings... and modify accordingly
0
 
LVL 10

Assisted Solution

by:eeBlueShadow
eeBlueShadow earned 41 total points
ID: 10902090
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
0
 
LVL 53

Assisted Solution

by:COBOLdinosaur
COBOLdinosaur earned 41 total points
ID: 10903149
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 );
      xml.Send()
       }
      catch (e) {
      var xml = new ActiveXObject("MSXML2.XMLHTTP.4.0");
      xml.Open( "GET", url, false );
      xml.Send()
      }
   }
   else
   {
      // Mozilla/Netscrap 6+ version
            var xml=new XMLHttpRequest();
            xml.open("GET",url,false);
            xml.send(null);
   }
}/*
Now you can test the status. You can find the HTTP status codes here:
http://www.w3.org/Protocols/HTTP/HTRESP.html
*/
if (http.status == 404 || http.status == 500) {
// Do something because the page cannot be accessed
   location.href="notfound.htm";
}
if (http.status == 200) {
// Do something because the page does exist
   location.href="http://domain.site.com/page.htm"
// of course you could also used what has already been retrieved
// with document.documenElement.innerHTML=xml.responseText
}
}
//-->
</script>

Cd&
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Find out what you should include to make the best professional email signature for your organization.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

827 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question