Solved

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

Posted on 2004-04-23
5
170 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

757 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

16 Experts available now in Live!

Get 1:1 Help Now