<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Isak Rubin</title>
	<atom:link href="http://isakrubin.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://isakrubin.com</link>
	<description>Make it work - Then write the code</description>
	<lastBuildDate>Sat, 25 May 2013 11:09:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>Temporarily take your site down</title>
		<link>http://isakrubin.com/take-your-site-down-temporarily-503-unavailable/</link>
		<comments>http://isakrubin.com/take-your-site-down-temporarily-503-unavailable/#respond</comments>
		<pubDate>Sat, 29 Oct 2011 23:56:52 +0000</pubDate>
		<dc:creator><![CDATA[Isak]]></dc:creator>
				<category><![CDATA[Server stuff]]></category>
		<category><![CDATA[503]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[service unavailable]]></category>
		<category><![CDATA[temporarily]]></category>
		<category><![CDATA[unavailable]]></category>

		<guid isPermaLink="false">http://isakrubin.com/?p=76</guid>
		<description><![CDATA[Temporarily taking our sites down is something we all are trying to avoid, but there are times when it&#8217;s necessary. Maybe you&#8217;ve been hacked, maybe you need to move a backend server, or maybe you just need to take the site down for some maintenance work that can&#8217;t be done whilst online. Whatever the reason is, [&#8230;]]]></description>
				<content:encoded><![CDATA[<p><!-- B2GSRCCGXFH4  --><br />
<a href="http://isakrubin.com/take-your-site-down-temporarily-503-unavailable/"><img class="alignright size-full wp-image-107" title="Temporarily unavailable" src="http://isakrubin.com/assets/2011/10/temporarily-unavailable1.png" alt="Temporarily unavailable" width="300" height="86" /></a>Temporarily taking our sites down is something we all are trying to avoid, but there are times when it&#8217;s necessary.</p>
<p>Maybe you&#8217;ve been hacked, maybe you need to move a backend server, or maybe you just need to take the site down for some maintenance work that can&#8217;t be done whilst online.</p>
<p>Whatever the reason is, even if it&#8217;s just <em>temporarily</em> it&#8217;s essential that it&#8217;s taken down properly.</p>
<p><strong>Do not</strong> simply leave an infected or erroneous page, it will send a <strong>200 code</strong> to the client, basically saying all is good, resulting in GoogleBot etc indexing your erroneous content.</p>
<p><strong>Do not</strong> just put up a page temporarily with a message to your visitors that you will be right back, for the same reason as above. Visiting bots will think everything is cool and index your temporary page. Which is exactly what happend to disney.com a little while ago. They had their temporary page show up first thing on Google for a long time.</p>
<p><strong>Do not</strong> just deny access temporarily ( <strong>403 code</strong> ), it will also cause problems. Visitors including bots have no way of knowing if this is for 5 minutes or permanently, which might get your pages deindexed.</p>
<p><strong>Do</strong> make sure to make both your visitors and visiting bots aware that the site is just <strong>temporarily</strong> down.</p>
<p>There is different ways of doing this, but they all include sending the client a &#8220;<strong>503 service unavailable</strong>&#8221; code.</p>
<p>Sending the client a &#8220;<strong>503 service unavailable</strong>&#8221; code will tell visitor that the site is down <strong>temporarily</strong> and not permanently, GoogleBot and most other bots respects this and will come back later.</p>
<p>Here&#8217;s a few examples on how to take your site down temporarily using <strong>php</strong> and <strong>apache</strong> or <strong>nginx.</strong></p>
<p>&nbsp;</p>
<h2>Apache .htaccess</h2>
<pre>ErrorDocument 503 "We are <em>temporarily</em> down due to... Back at..."
RewriteEngine On
# Put your own ip below to be able to allow yourself access
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123$
RewriteRule .* - [R=503,L]</pre>
<p>This works fine and allows you to show a message to your visitors about why the site is <em>temporarily</em> down and when it&#8217;s expected to be back up.</p>
<p>However, spiders and bots won&#8217;t understand that. They will know that the site is <span style="text-decoration: underline;">temporarily</span> down, but they will not know when it&#8217;s expected to be back up.</p>
<h2>Nginx</h2>
<pre>location / {
  if (-f $document_root/maintenance.html) {
    return 503;
  }
  ..... rest of your normal config here
}

error_page 503 @maintenance;
location @maintenance {
rewrite ^(.*)$ /maintenance.html break;
}</pre>
<p>&nbsp;</p>
<p>To put your site into maintenance mode simply put a message into the maintenance.html file, and remove it once finished.</p>
<p>This is similar to the apache version above, it works and it shows a message to the user letting them know the site is <strong>temporarily</strong> down, but it doesn&#8217;t let the clients/spiders know when the site is expected to be back up.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<h2>PHP</h2>
<pre>&lt;?php
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');
print "We are having some issues, check back in a while";</pre>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>In the code above we first set the header with the <strong>503 Service Temporarily Unavailable</strong> code, but then we also add the &#8220;<strong>Retry-After</strong>&#8221; part of the header, telling the client/bot when it should retry the page again.</p>
<p>In our case we tell the client to retry after 3600 seconds, ie 1 hour.</p>
<p>To get this to work with <strong>apache</strong> we can use the following in our <strong>.htaccess</strong> file ( remember to replace /var/ww with the actual path to your file ).</p>
<pre>RewriteEngine On
RewriteRule .* /var/www/maintenance.php</pre>
<p>&nbsp;</p>
<p>This will redirect all requests to your maintenance page and at the same time telling the client to revisit after 1 hour.</p>
<p>&nbsp;</p>
<p><strong>Nginx</strong> version below</p>
<p>&nbsp;</p>
<pre>if (-f $document_root/maintenance.php) {
  return 503;
}

error_page 503 @maintenance;
location @maintenance {
  fastcgi_pass   localhost:9000;
  fastcgi_param  SCRIPT_FILENAME $document_root/maintenance.php;
  fastcgi_param  PATH_INFO $fastcgi_script_name;
  include /etc/nginx/fastcgi_params;
}</pre>
<p>And just like the <strong>apache</strong> version above this will also <strong>redirect</strong> all requests to your <strong>maintenance</strong> page and at the same time telling the client to revisit after 1 hour.</p>
<p>&nbsp;</p>
<p>Google them selves recommend this way of <a title="taking a site down temporarily" href="http://googlewebmastercentral.blogspot.com/2011/01/how-to-deal-with-planned-site-downtime.html">taking a site down temporarily</a>.</p>
<p>So the next time you&#8217;re taking your site down <em>temporarily</em>, at least do it correctly :)</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://isakrubin.com/take-your-site-down-temporarily-503-unavailable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
