Solved

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

Posted on 2004-04-23
5
171 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction The Google Maps API offers various ways to draw dynamic and static maps.  Using a combination of PHP and JavaScript, you can draw active JavaScript maps that allow pan-and-zoom in the client browser window.  You can also draw "static" …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now