views:

34

answers:

1

Hi,

Is there a way to provide fallback URL when HTTP redirect times out? What I'm trying to achieve is that when I hit the original url, I would respond with HTTP redirect (300, 307?) giving the browser new URL and the fallback URL in case the new URL times out?

I was also considering doing this client side but it just does not seem to be very effective (in terms of speed, client support). What I would do is probably have a tiny 1x1px image on each server, try loading it and then check with javascript which server is up and redirect there.

Any other ideas? Thanks

+2  A: 

I think this can be done only through JavaScript. You could do a quick server side test before sending out the redirect, but that would not be reliable - especially if the servers are in the same server farm.

The most reliable thing would surely be to have a JavaScript, have that make a quick Ajax request (HEAD only) to the server, and redirect on success. If it fails, try the next server... and so on.

Is this really necessary, though? If the target server has so many outages that you need to react to them programmatically, it may be worth looking into relocating the server (or doing whatever is needed to fix the outages).

Pekka
Actually, the reason for doing this was bit different. I was trying to do something "new", not prevent server outages. I guess if there is no other way than javascript then it is not worth doing - for performance reasons. Thanks anyway
Ondrej Stastny
@Ondrej you're welcome. What you could do, if you know the redirect targets beforehand, is poll/ping them frequently in a background process, and maintain a kind of blacklist with alternative targets. That way, the act of checking the reachability would be independent from the client's request. Maybe that's an option (depending on what you want to do).
Pekka