31.01.2021

Installing the last modified module in apache. A blog that has a lot of interesting information…. Why are Last-Modified and If-Modified-Since headers needed


“In particular, the content of the response that the server sends to the“ if-modified-since ”request is important. The Last-Modified header must return the correct date last change document. "

Let's check how things are with Last-Modified in various CMS.

# telnet www.example.com 80

and enter the following:

GET /index.html HTTP / 1.0 User-Agent: Mozilla / 5.0 From: something.somewhere.net Accept: text / html, text / plain, application / * Host: www.example.com If-Modified-Since: Wed, 19 Oct 2005 10:50:00 GMT

if the server returns 304 (Not modified), then it supports If-Modified-Since, but the page has not been modified. Code 200 (Ok) means the page has been changed.

Checking If-Modified-Since in C #

You can check how If-Modified-Since works using the following C # code:

Private HttpWebResponse GetPage () (string url = @ "http: // ....."; // Place the web request to the server by specifying the URL HttpWebRequest request = (HttpWebRequest) WebRequest.Create (url); // No need for a persistant connection request.KeepAlive = false; // The link that referred us to the URL request.Referer = url; // The user agent of the browser request.UserAgent = "Mozilla / 4.0 (compatible; MSIE 7.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50215)"; // Instead of HTTP 1.1 I will use HTTP 1.0. When a request tells the server it uses 1.0, // the server won "t respond with chunked data but will send the response all at once. Request.ProtocolVersion = new Version (1, 1); request.IfModifiedSince = DateTime.Now. AddDays (-5); // Get the response from the server return (HttpWebResponse) request.GetResponse ();) private void TestLastModified (VirtueMartContext db, jos_vm_product product) (using (HttpWebResponse response = GetPage ()) (Debug.Print "Status Code: (0), Description: (1) \ n", response.StatusCode, response.StatusDescription); string text = WebResponceReader.GetResponceText (response); Debug.Print (text.Substring (0, 100)); ))

using this method, you can ensure that Joomla always returns StatusCode = 200 (OK), regardless of the value of request.IfModifiedSince.

If-Modified-Since check via Yandex service

If you click on the "Check server response" button in Yandex Webmaster, we get here:

here again you can see that the site site and, accordingly, WordPress without the WP Super Cache plugin does not add the Last-Modified header.

Well, we figured out the CMS, but how does Yandex work?

Here you can give an example: today is 7.7.2011, the content in Joomla was updated on 20.6.2011, and Yandex has a cache version of 11.06.2011, although after this date the robot has already come several times. In this case, Yandex downloads updates with a very significant delay. The question is why?

Here is what Platon Shchukin says about this:

As it crawls the site, the robot will also crawl the specified page, after which it will be updated in the SERP when the search databases are updated. We are working to make this happen as quickly as possible.

For your part, you can also help the robot to index the site faster by using the following recommendations from

Syntax

If-Modified-Since: , ::GMT

Directives

One of "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", or "Sun" (case-sensitive). 2 digit day number, e.g. "04" or "23". One of "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ( case sensitive). 4 digit year number, e.g. "1990" or "2016". 2 digit hour number, e.g. "09" or "23". 2 digit minute number, e.g. "04" or "59". 2 digit second number, e.g. "04" or "59". GMT

Greenwich Mean Time. HTTP dates are always expressed in GMT, never in local time.

Examples

If-Modified-Since: Wed, 21 Oct 2015 07:28:00 GMT

Specifications

Specification Title
RFC 7232, section 3.3: If-Modified-Since Hypertext Transfer Protocol (HTTP / 1.1): Conditional Requests

Browser compatibility

The compatibility table in this page is generated from structured data. If you "d like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.

Update compatibility data on GitHub

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
If-Modified-SinceChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support YesOpera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yes

The Last-Modified HTTP header tells the client the time the page (object) was last modified. If the client (browser, search robot) received the Last-Modified header, then at the next access to the address, provided that the page (object) is in the local cache, it will add the question If-Modified-Since (has the page changed after the date, obtained in Last-Modified). In turn, the server, having received the If-Modified-Since request, must check the received timestamp with the time the page was last modified and, if the page has not changed, respond with 304 Not Modified.

Saving Traffic

If the page has not changed, the server will stop transmitting data after sending headers with the 304 Not Modified code, the page body, images and other objects will not be transmitted.

Reducing server load

Correct implementation of checking the time of the last page change can significantly (up to 30% or more) reduce the load on the server. Correct implementation means checking the time before the start of page generation on a dynamic site. In this case, all actions to generate the page (requesting content from the database, parsing templates, receiving comments, etc.) will not be performed. This is especially true for sites with high traffic and long duration of the user's visit. Example: A user is on a sports news site and constantly refreshes the home page pending the publication of the match result. In a few minutes, a page can be requested and received dozens of times. If the Last-Modified header is given and the If-Modified-Since request is processed correctly, then the page will actually be transmitted once, and a 304 Not Modified response will be returned to all subsequent requests.

Speed ​​up indexing by search engines

Search engines the webmaster guide recommends sending the Last-Modified header and handling If-Modified-Since correctly.

I didn't have any sorrow until I installed the Seo Scan plugin for myself today. Nice plugin that shows what google might not like about your site and server. And my site didn’t like something for sure - it’s the absence of last-modified .


A bit of theory, I just learned about it myself today. Last-modified is an http header that sends a signal about whether a certain page has been modified or not by sending an If-Modified-Since response with a 304 code. Something like this ...

Although without all this, the site will be indexed, as Yandex says, but there are significant disadvantages in the absence of this title:

  • the date will not be shown in the search results next to the site pages;
  • when sorting by date, the site will not be visible to users;
  • the robot will not be able to get information about whether the site page has been updated since the last indexing. And since the number of pages received by the robot from the site in one visit is limited, the changed pages will be re-indexed less often.

As you can see, there are many disadvantages, and first of all, it is not very fast indexing and re-indexing of the site. That is, you made a USEFUL change to the article, and now I do a lot of them every day, and Yandex and Google can see it's only a couple of months! No, we don’t need this kind of hockey, now I’ll break into a cake, but I will correct this defect!

How to check last-modified?

You can check different ways, in wordpress the easiest thing is to install the above plugin Seo Scan, he gave me this:

It also junk, but that's another story, then I dig deeper into this. You can also check last-modified via the service of the same name last-modified.com


As you can see, it also shows the absence of an If-Modified-Since response - Last Modifed not found! Or you can use the Yandex service Checking server response


It's the same here - HTTP status code:"304 Not Modified" means the system is not working. Although the obvious error disappeared after a while, the 304 response code never appeared.

It immediately became interesting, but does it work for anyone? I decided to check this with those bloggers who themselves wrote manuals on this topic:


Yes, the guy from the TOP for this query found Last-Modified, which means it is possible for me as well. By the way, his article lists many ways to configure Last Modified, let's try them, although I found others.

How do I set up last-modified?

I will describe all the methods that I tried and immediately say whether it worked for me or not. But keep in mind that if it didn’t work for me, it doesn’t mean that it won’t work for you.

1. The first way is to install the plugin

The easiest way for those who have WordPress is to install plugins for this purpose, for example: Add Headers, If Modified Since, or If Modified Since Header.

None of these plugins gave a result for me, I don't know why. Can it work for you?

2. Second way - PHP code

Service last-modified.com, described above, suggests in the header.php file, at the very beginning, to put the following php code:

= $ LastModified_unix) (header ($ _ SERVER ["SERVER_PROTOCOL"]. "304 Not Modified"); exit;) header ("Last-Modified:". $ LastModified); ?>

It didn't help me either. I also suggest trying to place it in the index.php file in the root of the site, but that didn't help me either.

3. The third way is to write to .htaccess

If you have a server on Apache, then most likely it will work for you. Need to file .htaccess in the root of the site, insert the code:

RewriteRule. * - RewriteRule. * -

It didn't work for me, since I have a bundle of Ngnix + Apache and all these manipulations with .htaccess most often do not work.
After all these torments I thought: why am I the only one suffering? I will write how to the hosting support service, there are people who are literate, can they tell me? I wrote, I'm sitting waiting.

The answer came from technical support:

It's simple. Your site pages are generated by php-scripts that do not give this header to the browser.
Web server (nginx) for static files(jpg, gif, css, js, etc.) gives in the header the last-modified date of the last modification of the file. Examples in the screenshots.
If you do not have a very large site traffic, then there is no point in caching site pages on the browser side.

Why is this post under the heading SEO? Last modified, as the search engines assure, is a very important http header, which is needed in order to report the date of the last modification of the document, that is, the date of the last change on the page.

Accordingly, if this title is not there, or rather it will not be rendered, then the site will lose some of its advantages. In particular, here's what I read about the benefits of last modified:

  1. The speed of indexing new pages improves, and the robot can take more pages into the index per visit.
  2. Improves the speed of reindexing pages that you have made changes to. This is very useful, but without this header, your edits will take longer to track.

In principle, this is already enough to make you want to check and, if necessary, adjust this header.

How to check last modified?

There are several tools, I liked this one the most - http://www.tools.seo-auditor.com.ru/if-modified-since/
Here I just need to enter the address home page or any article, and then choose search robot- Yandex.

Last Modified was found on my website, it's great. But initially it was not there, how did I set it up?


How to set up last modified?

To be honest, nothing helped me. Maybe due to the fact that nginx server... I installed AddHeaders - this plugin puts all useful http-headers, including last modified, but this plugin did not help me, although about a year ago it successfully activated this header on my site.

Also on this blog I put the premium Clearfy plugin I wrote about. A useful gizmo, there is also a function that would allow you to put last modified.

I activated the option, but the title was still not returned based on the check results. But in the end, everything was decided by the appeal to those. plugin support - there I described the configuration of my server and they gave me specific advice - go to the server control panel, disable this and that. No sooner said than done, and now the title is served.

I think adding a title will have a positive impact on my sites.

One-stop solution- the AddHeaders plugin is most likely suitable for you if you have an apache server. If nginx, then try disabling ssi in the domain settings and again activate this plugin.


2021
maccase.ru - Android. Brands. Iron. news