Redirect Users when your site is down

By codedexter11 on Jun 15, 2013

It allows you to show you helpful message to site visitors during the down time of your website.

<?php

$host = 'www.volk37.com';

$up = ping($host);

// if website is up, show the message on site.

if( $up ) {

        header('Location: http://'.$host);

}

// If the site is down 

else {
        header('Location: http://www.someothersite.com/helful_message');
}

?>

Comments

Sign in to comment.
Hawkee   -  Jun 15, 2013

Interesting, but if the site is down how will this script get executed?

ProIcons  -  Jun 16, 2013

His concept is that both sites, Main and Sub are not in the same server, neither this script is. So he will assign AN A Record to his dns on the server that holds this script, he will make a different A Record for the main site, on the other server, and another a record on another server with the sub site. So when his dns goes off this won't work either. Dunno it was just a guess

Hawkee  -  Jun 17, 2013

@ProIcons Sounds reasonable. Would love to hear from the developer.

[nas]peter  -  Jun 19, 2013

Why wouldn't you just use HAProxy with keepalived? That would work just as well...

deleteme1  -  Jul 24, 2013

One problem with this, is it would take longer to execute (talking very little here), you are using variables when they are not needed.

This would take less time to execute :

<?php

// if website is up, show the message on site.

if( ping(www.volk37.com) ) {

        header('Location: http://www.volk37.com');

}

// If the site is down 

else {
        header('Location: http://www.someothersite.com/helful_message');
}

?>
Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.