Bitrix: setting If-Modified-Since headers
Битрикс: устанавливаем If-Modified-Since заголовки

All English-language materials have been translated fully automatically using the Google service

The heading Last-Modified is a fairly common wish of seo specialists. Unfortunately, Bitrix does not allow setting last-modified headers out of the box. So I applied a trick: I split all pages into 2 boolean types - static and dynamic.

- For static pages I set the title by the time of the last modification of the file in which they are located.

- For dynamic pages in each template, I display the last modification of the page by the time the last element was added or updated.

Providing headings

In init.php we write

  / * Expose headers if-modified-since * /
require ($ _ SERVER ['DOCUMENT_ROOT']. '/ local / libs / if-modified-since.php');  

In if-modified-since.php

  / * Expose headers if-modified-since * /
AddEventHandler ('main', 'OnEpilog', array ('CBDPEpilogHooks', 'CheckIfModifiedSince'));
class CBDPEpilogHooks
    function CheckIfModifiedSince ()
        GLOBAL $ lastModified;

        if (! $ lastModified) $ lastModified = time () - rand (1000, 100000);

        if ($ lastModified)
            header ("Cache-Control: public");
            header ('Last-Modified:' .gmdate ('D, d M Y H: i: s', $ lastModified). 'GMT');

            if (isset ($ _ SERVER ['HTTP_IF_MODIFIED_SINCE']) && strtotime ($ _ SERVER ['HTTP_IF_MODIFIED_SINCE'])> = $ lastModified) {
                header ('HTTP / 1.1 304 Not Modified'); exit ();

If-Modified-Since for static pages

Write somewhere in the file.

  GLOBAL $ lastModified;
if (! $ lastModified) {
    $ lastModified = strtotime (date ("D, d M Y H: i: s", filectime ($ _ SERVER ['SCRIPT_FILENAME'])));
} else {
    $ lastModified = max ($ lastModified, MakeTimeStamp ($ arResult ['TIMESTAMP_X']));

If-Modified-Since for dynamic list of items

In result_modifier.php

  if (! empty ($ arResult ['ITEMS'])) {
    $ time = strtotime ("- 5 years", time ());
    $ date = date ("Y-m-d", $ time);

    $ dat ['DATE'] = $ date;
    foreach ($ arResult ['ITEMS'] as $ key => $ value) {
        if ($ value ['DATE_CREATE'] && strtotime ($ dat ['DATE'])  __ component-> arResult ["LAST_MODIFY"] = $ dat ['DATE'];
    $ this -> __ component-> SetResultCacheKeys (array ("LAST_MODIFY"));

In component_epilog.php

  GLOBAL $ lastModified;
$ lastModified = strtotime ($ arResult ['LAST_MODIFY']);  

If-Modified-Since for complex component detail pages

In component_epilog.php

  GLOBAL $ lastModified;
$ m = $ arResult ['TIMESTAMP_X']? $ arResult ['TIMESTAMP_X']: $ arResult ['DATE_CREATE'];

if (! $ m) {
    $ lastModified = strtotime (date ("D, d M Y H: i: s", filectime ($ _ SERVER ['SCRIPT_FILENAME'])));
} else {
    $ lastModified = MakeTimeStamp ($ m);

Do not forget to select "Creation date" and "Modification date" in the fields for displaying in the settings of complex components

After adding the code, you will need to update the component cache or completely reset it

I have not tested the compatibility of this solution with the composite

The best place to check the returned headers is here: Last-

The solution was applied on the Business v17.5.4 edition


There are no comments yet, you can be the first to leave it

Leave a comment

The site uses a comment pre-moderation system, so your message will be published only after approval by the moderator

You are replying to a user's comment



Email me

Are you developing a new service, making improvements to the existing one and want to be better than your competitors? You have come to the right place. I offer you a comprehensive studio-level website development. From me you can order design, layout, programming, development of non-traditional functionality, implementation of communication between CMS, CRM and Data Analitics, as well as everything else related to sites, except for promotion.

Contact, I will always advise on all questions and help you find the most effective solution for your business. I am engaged in the creation of sites in Novosibirsk and in other regions of Russia, I also work with the CIS countries. You will be satisfied with our cooperation

An error occurred while sending, please try again after a while
Message sent successfully


+7(993) 007-18-96



Россия, г. Москва

By submitting the form, you automatically confirm that you have read and accept the Privacy Policy site

Contact with me
Send message
By submitting the form, you automatically confirm that you have read and accept Privacy policy of site
Sending successful!
Thank you for contacting :) I will contact you as soon as possible
Sending failed
An error occurred while sending the request. Please wait and try again after a while or call my phone number