Ad

HTTP IF MODIFIED SINCE Page Headers For Google

- 1 answer

Logic: to speed up the indexing of new products and new pages, as well as redefining changes on the page, to reduce the load on the hosting, you need to adjust to give the server headers MODIFIED_SINCE.

Error: I met a lot of code examples when the date of the document update was the current time at the time of the request to the page. It is fundamentally wrong because in the end you are deceiving yourself and forcing the search engine to spend more on crawling pages, and the search engine allocates limits on re-indexing.

Ad

Answer

Not obvious: this header appears once in a variable. $_SERVER['HTTP_IF_MODIFIED_SINCE'] if the page request happens again, it will not be in the variable. Easy to miss. Carefully!

1. First, in order for the server to give these headers you need to configure config (nginx: if_modified_since exact). http://nginx.org/ru/docs/http/ngx_http_core_module.html#if_modified_since

Reload server.

2. PHP at the top of index.php

`$LastModified_unix = $date_changed; // timestamp of document change
 $LastModified = gmdate("D, d M Y H:i:s \G\M\T", $LastModified_unix);
 $IfModifiedSince = '';
 if (isset($_ENV['HTTP_IF_MODIFIED_SINCE'])){
 $IfModifiedSince = strtotime(substr($_ENV['HTTP_IF_MODIFIED_SINCE'], 5));
 }
 if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])){
 $IfModifiedSince = strtotime(substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 5));
 }
 if ($IfModifiedSince && $IfModifiedSince >= $LastModified_unix) {
 header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
 exit;
 }
 header('Last-Modified: ' . $LastModified);`

3. Header Checker Service: https://last-modified.com

It is important to remember: after the introduction you get the correct crawl by search engines, but at the same time the pages without changes will age for search engines. But you will know for sure that the new and updated content will be quickly taken into account.

Worked on the showers shop https://www.remontbistro.ru it has correct headers. If someone does not understand something, write prompt.

We have been looking for a long time how to correctly implement the recommendation of search engines for setting up headings. In different places bit by bit found. Without a clear algorithm, the setup took 1 day.

Ad
source: stackoverflow.com
Ad