Last-Modified does not work for .htaccess

I use tyring to implement browser caching and follow Google PageSpeed's recommendations on setting Last-Modified to data that is "quite far in the past." I have the following in my .htaccess:

<IfModule mod_headers.c>
 <FilesMatch "\.(json|pdf|swf|bmp|gif|jpeg|jpg|png|svg|tiff|ico|flv|js)$">
  Header Set Last-Modified "Fri, 01 Jan 2010 12:00:00 GMT"
 </FilesMatch>
</IfModule>

I have mod_headers installed on my server.

Unfortunately, Google PageSpeed ​​is still complaining and warning me:

Leverage browser caching

The following cacheable resources have a short freshness lifetime. Specify an expiration at least one week in the future for the following resources:

And then lists PNG, GIF, JPG, etc. Yahoo YSlow says basically the same thing.

Looking at the response headers of one of my resources that should be cached, I see the following:

Date:           Tue, 19 Oct 2010 20:12:04 GMT
Server:         Apache/2.2.14 (Ubuntu)
Last-Modified:  Tue, 07 Sep 2010 23:51:33 GMT
Etag:           "2e0e34-2a43-48fb413a96a20"
Accept-Ranges:  bytes
Content-Length: 10819
Content-Type:   image/png

As you can see, the Last-Modified data does not match what I specified in .htaccess.

Any ideas what I'm doing wrong?

+3
3

, unset Last-Modified?

:

<IfModule mod_headers.c>
 <FilesMatch "\.(json|pdf|swf|bmp|gif|jpeg|jpg|png|svg|tiff|ico|flv|js)$">
  Header unset Last-Modified
 </FilesMatch>
</IfModule>

FilesMatch , , , Header Set. , . Header set Header set

, , , . Unset ,

+2

Last-Modified Google PageSpeed. , :

Cache-Control max-age=...
Expires ...

.

.htaccess :

<IfModule mod_headers.c>
 <FilesMatch "\.(json|pdf|swf|bmp|gif|jpeg|jpg|png|svg|tiff|ico|flv|js)$">
  ExpiresActive On
  ExpiresDefault "access plus 1 year"
  Header append Cache-Control "public"
 </FilesMatch>
</IfModule>

, Google PageSpeed ​​ .

+6

:

<IfModule mod_expires.c>
# Enable expirations
ExpiresActive On 
# Default directive
ExpiresDefault "access plus 1 month"
# My favicon
ExpiresByType image/x-icon "access plus 1 year"
# Images
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
# CSS
ExpiresByType text/css "access 1 month"
# Javascript
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
0

Source: https://habr.com/ru/post/1770622/


All Articles