Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

This question already has an answer here:

I've to do some big works to my website, so I've to put it offline for some hours, but I don't want to lose my rank in google. I've read this tutorial: http://www.branded3.com/blogs/handle-googlebot-during-site-downtime/ This is the correct procedure, right?

I've also another question. Where should I put this code?

<?php
header("HTTP/1.1 503 Service Temporarily Unavailable");
header("Status: 503 Service Temporarily Unavailable");
header("Retry-After: 3600");
php?>

In the index.php, ora in a new page named errorpage.php in the root? Google will find this automatically?

Thanks!

share|improve this question

marked as duplicate by bybe May 4 at 13:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1  
I'm not sure about the Status header - that's non-standard and unnecessary IMO. See also these other questions: How do I temporarily disable a website? and How to set restrictions on my website? –  w3d May 4 at 11:11
1  
@w3d +1 for the links (I think this one is a duplicate), but the Status header is required for fastcgi –  Yogu May 4 at 13:00
    
Do you mean that I can remove this line? header("Status: 503 Service Temporarily Unavailable"); I'm sorry but I really don't have idea about how these things work. –  daimpa May 4 at 21:16
    
@Yogu Thanks for the info regarding the Status header and FastCGI. However, I think if PHP is configured properly then this should be unnecessary (PHP should convert it as reqd)? See this SO question: stackoverflow.com/questions/8828275/… –  w3d May 7 at 22:44
    
@daimpa: In theory, yes. However, as Yogu mentioned, this can depend on your server. Both the HTTP/1.1... and Status: lines do the same thing but in different server environments. Ideally, you should only need the first one (and PHP should convert it as reqd). (You should still use the Retry-After header.) –  w3d May 7 at 22:49

1 Answer 1

It depends on your application. If your application has a front controller like WordPress, then you can use index.php to make the complete site offline, since all requests go via index.php.

If your application consists of individual PHP files, then you have to put the code to each file.

share|improve this answer
    
If you have a collection of files (the 2nd part of this answer), you can use a .htaccess to rewrite all pages to your temp-unavailable.php –  Martijn May 4 at 11:37
    
So, if I put this on my .htaccess in the root, I've done everything correctly? Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{HTTP_USER_AGENT} ^.*google.* [NC] RewriteRule .* /errorpage.php –  daimpa May 4 at 21:17

Not the answer you're looking for? Browse other questions tagged or ask your own question.