Click to See Complete Forum and Search --> : How to make a script that Redirects if a page or file does not exist
Dark_Icer
10-06-2003, 03:40 PM
I am not trying to make an error page. What I am try to accomplish is a script that check to see if a file(paticulary a web page file *.html) exists, and redirects to an alternative location if it does not exist.
In other words i am looking for a script that would redirect to the mirror of the file or page on another location on another server.
If I could use C++ I would have just done
fstream check("file.html");
if(check.open==fail)
//some code to load from another location
//or error messege
else
LoadMe(check);
// load the file or object
Could somebody help me with this please?
Dimitri
10-06-2003, 06:00 PM
What you're trying to do is impossible with client side scripting.
You need server side code to do that (Perl, C++, JSP, PHP, etc., or if you're using Apache, you can modify it to automatically redirect 404 errors to a customized error page on the server.)
Dimitri
Dark_Icer
10-09-2003, 01:20 AM
But would it be possible to create a Java Applet to do my biding.
WhatI am trying to do is make an a page that will detect wheather or not my server is up or not and if it's not it will continue to load from my free web space server and not from my home server. Like Direct Connect used to do when it was free.
Dimitri
10-09-2003, 01:31 PM
Using an applet to connect to a different domain is not allowed. The security level of the browser JRE, by default, prevents applets from connecting to a different domain than the one that the applet was loaded from.
Also, assuming your servers were part of the same domain (server1.foo.com and server2.foo.com) it still would cause serious problems because you'd be forcing the user to wait, after they've clicked a link, for a hidden applet to connect to the page (via LiveConnect) and wait for a server response (which can take a long time if the server is slow, or is down, or the user's internet connection is slow).
It's just not a good idea to do that. As a user, I would leave your website after about 10 seconds (which is not your intent, I'm assuming.)
Sorry.
Dimitri