I’m considering using the following code during a website launch phase to show users a down for maintenance page while showing me the rest of the site.
Is there a way to show the correct 302 re-direction status to search engines or should I look for another .htaccess based approach?
$visitor = $_SERVER['REMOTE_ADDR'];
if (preg_match("/192.168.0.1/",$visitor)) {
header('Location: http://www.yoursite.com/thank-you.html');
} else {
header('Location: http://www.yoursite.com/home-page.html');
};
For a
302 Found, i.e. a temporary redirect do:If you need a permanent redirect, aka:
301 Moved Permanently, do:For more info check the PHP manual for the header function Doc. Also, don’t forget to call
exit;when usingheader('Location: ');But, considering you are doing a temporary maintenance (you don’t want that search engines index your page) it’s advised to return a
503 Service Unavailablewith a custom message (i.e. you don’t need any redirect):