Sometimes your website needs downtime so you can fix things or update plugins. This is usually a relatively short period of time in which Google will probably not try to crawl your site. In case you need more time to fix things, the chances are much greater GoogleBot you may be visited and confronted with a website that is not available. So how can we prevent Google from withdrawing your site?

HTTP status codes and you

For those unfamiliar with HTTP status codes, here’s a brief summary of those that apply to you when dealing with site maintenance:

  • 200 OK. This status code determines that the server was successful in returning a response.
  • 301 permanently moved. This indicates to the reader that this page is no longer valid and will lead to the correct page.
  • 302/307 Temporarily moved. There is a history behind these two HTTP status codes, but what it prescribes for the browser is that you will temporarily redirect the browser to another page and that the current URL will eventually return to its previous state.
  • 404 not found. This status code means that the page you are trying to navigate could not be found.
  • 410 Content deleted. Use it if you have intentionally deleted your content and there is no replacement. Find out more about how to delete pages properly.
  • 503 Service Unavailable. This is the one you want to send back to Google if you are dealing with site maintenance. This tells Google that you’m actually working on this page or that something else went wrong. Google knows that when this status code is returned, the page will be revisited later. This is what we will discuss a little more.

Note that Google will consider pages that return the 200 HTTP status code, even though there is an error (or very little content) on the page, as a “sag 404“In Google Search Console.

Read more: HTTP Status Codes »

To tell Google that you’m busy

If Google hits a 404 while crawling your site, it will usually throw that page out of the search results until it returns next time to verify that the page is back. However, if Google repeatedly hits a 404 on that particular page, it will eventually delay the crawl, which means more time will pass before the page returns in the search results.

To overcome this potential longer loss of rankings, you must return a 503 status code when working on a specific page. The original definition of the 503 status code, according to this RFC, is:

The server is currently unable to handle the request due to a temporary overload or maintenance of the server. The implication is that it is a temporary condition that will be delayed to some extent. If known, the length of the delay MAY appear in a retry header. If no retry-after is given, the customer MUST treat the answer as for a 500 answer.

What this means is that bringing back a 503 in combination with a Retry-After headline, which will tell Google how many minutes to wait before returning. It do not this means that Google will crawl again in exactly X minutes, but it will ensure that Google does not come back to look before.

Add the heading

If you want to implement the heading, there are a few options from which to choose.

Using the WordPress standard is

By default, WordPress already yields a 503 when plugins or WordPress core are updated. With WordPress you can replace the default maintenance page with a maintenance.php to you wp-content/ guide. Note that you will then be responsible for returning the 503 header properly. Are you planning to do database maintenance? You will also need to take care of it. Add a db-error.php file to you wp-content/ and make sure you also return a 503 heading properly here.

Check it out if you want to add something more popular to your WordPress site WP maintenance mode. This plugin also adds a lot of extra features besides what we mentioned in the previous section.

If you just write your own code and want a solution that is easy to implement, you can add the following snippet to your code base and mention it in the code that determines if you are in maintenance mode:

function set_503_header() {
    $protocol="HTTP/1.0";

    if ( $_SERVER['SERVER_PROTOCOL'] === 'HTTP/1.1' ) {
        $protocol="HTTP/1.1";
    }

    header( $protocol . ' 503 Service Unavailable', true, 503 );
    header( 'Retry-After: 3600' );
}

Note that the 3600 in the code snippet determines the delay time in seconds. This means that the above example will tell GoogleBot to return after one hour. It is also possible to insert a specific date and time Retry-After, but you should be careful about what you add here, as adding an incorrect date can lead to unexpected results.

Pro tips

Caching

There are a few things to keep in mind when working with interview pages and returning 503 status codes. If you use cache actively, you could end up in a situation where the cache does not pass 503 status properly, so be sure to test it properly before using it actively on the live version of your website.

Robots.txt

Did you know that it is also possible to return a 503 status code to your robots.txt? Google declares in its robots.txt documentation that you can temporarily suspend the crawl by throwing a 503 for your robots.xt file. The biggest advantage of this is less server load during maintenance periods.

Handle your maintenance well!

As you can see, you can avoid losing rankings by adding a 503 when you do website maintenance, letting Google know that it may come back later to crawl your website. There are different ways to do this. Choose what works best for you, and you will have a website that is well maintained and has no danger of losing rankings. Strength!

Keep reading: Which redirect should I use? »



Source link