Apache not sending Last-Modified header even if explicitly set - apache

I have a problem with the Last-Modified header.
I created a simple test page:
<?
header('Last-Modified: Thu, 14 Feb 2013 12:41:31 GMT');
?>
When I open this test page with my browser, if I check the headers there's no Last-Modified header. All the other standard headers are set correctly. Anyway, if I access the test page with https, the Last-Modified header is set.
I also tried the same test on another server, and I can see the header correctly set even without https.
So, what could block/unset the header on the first server? I'm not including the httpd.conf file because is very long. I'll just include the caching section, even if I don't see anything wrong or related to this problem:
ServerSignature Off
ServerTokens Prod
Header unset ETag
FileETag None
<FilesMatch "(?i)^.*\.(ico|flv|jpe?g|png|gif|js|css).*$">
Header set Cache-Control "public, no-transform"
Header unset Vary:
</FilesMatch>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A2592000
ExpiresByType text/css "access plus 1 week"
ExpiresByType text/plain "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
</IfModule>
Thanks in advance

try
ssi off;
in nginx config for this domain

There doesn't appear to be anything wrong with the header, but using <? ?> instead of <?php ?> can cause problems on some servers.

Related

is disabling ETAG and Last-Modifed a good option .htaccess

I'm using the below code for caching of files in .htaccess
<IfModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(css|scss)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|xml)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
#Header unset ETag
#Header unset Last-Modified
</IfModule>
I'm a bit confused if i should comment the #Header unset ETag and #Header unset Last-Modified or not
below is my default.conf file on apache
CacheQuickHandler off
CacheLock on
CacheLockPath /tmp/mod_cache-lock
CacheLockMaxAge 5
CacheIgnoreHeaders Set-Cookie
<Location />
CacheEnable disk
CacheHeader on
CacheDefaultExpire 600
CacheMaxExpire 86400
CacheLastModifiedFactor 0.5
ExpiresActive on
ExpiresDefault "access plus 1 week"
ExpiresByType image/x-icon "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 month"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/ld+json "acesss plus 1 day"
# This part sets the expires for the fonts
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType application/x-font-ttf "access plus 1 year"
ExpiresByType application/x-font-opentype "access plus 1 year"
ExpiresByType application/x-font-woff "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
#Header merge Cache-Control public
FileETag All
</Location>
Kindly anyone help me with this confusion what should i do to achieve maximum and best compression.
Etag and Last-Modified have nothing to do with compression, they are cache'ing options. Which is OK to unset anyway because they conflict with Cache-Control, which is a better cache method. So yes, you may disable it.
If you are looking for compression, look into Apache's mod_deflate, mod_gzip or mod_brotli.

expire headers and cache control with mod header

I have added expire header in my htaccess file so is there still need to add mod_header for cache-control?
My expire header is :
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
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"
ExpiresByType text/css "access 1 month"
ExpiresByType application/javascript "access plus 1 year"
</IfModule>
And My mod_header for cache-control is :
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\.(js|css|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
Let's read the documentation for mod_expires :
This module controls the setting of the Expires HTTP header and the
max-age directive of the Cache-Control HTTP header in server
responses. The expiration date can set to be relative to either the
time the source file was last modified, or to the time of the client
access.
The answer is therefore: It depends.
mod_expires sets the max-age directive, but does not set the directive that tells the client if the cache is public or private. When nothing is defined, I believe the cache will do a best-effort in determining if it wants to cache this particular response. On the other hand, it isn't possible to set the Expires-header with mod_header.
I think in your case the mod_header rules are obsolete, but you might want to inspect requests in your browser to see if caching happens as you expect.

Keep-Alive doesn't allow all persistent connections

I want to speed up my website. I runned test on http://www.webpagetest.org/ website that checks performance and optimization of website.
I enabled Keep-Alive inside .htaccess file. Problem is that result of testing says that only 18% of all connections are allowed (that ones that are linked or included via google)
ScreenShot:
Can someone explain to me how to allow all connection?
CODE THAT I USED:
<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>
<IfModule mod_headers.c>
<FilesMatch ".(js|css|xml|gz|html)$">
Header append Vary: Accept-Encoding
</FilesMatch>
</IfModule>
<IFModule mod_deflate.c>
<filesmatch "\.(js|css|html|jpg|png|php)$">
SetOutputFilter DEFLATE
</filesmatch>
</IFModule>
<IfModule mod_headers.c>
Header set Connection keep-alive
</IfModule>
Enable KeepAlive configuration in your Apache Configuration file
KeepAlive On

Disable/off Expires headers htaccess

earlier i tried to expires headers. but my site always update. then i put my expires headers to htaccess file. so now not get quick update from web browser. so its very dangerous for my site. now i want to disable it. how to do it and if someone know help for fix it to my site. my site is tv episode sites. so always update and css also update. here my .htaccess code
firstly give me to disable code
secoundly give me to fix this code to like our web site (tv episode site. from seconds upload any programs to our site)
/.htaccess
<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>
I was also looking for solving such a problem.
Even tried setting ExpiresActive Off - but that didn't help.
the only solution that worked was setting the date to 1 minute:
# CSS
ExpiresByType text/css "access plus 1 minutes"

htaccess file being ignored, trying to leverage browser caching for Pagespeed

I'm having a problem with my .htaccess file. I'm optimizing my site using Google Pagespeed and GTMetrix and both keep saying "leverage browser caching". So I just added my .htaccess file and included the following lines
## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##
# BEGIN Cache-Control Headers
<ifModule mod_headers.c>
<filesMatch "\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(css)$">
Header set Cache-Control "public"
</filesMatch>
<filesMatch "\.(js)$">
Header set Cache-Control "private"
</filesMatch>
<filesMatch "\.(x?html?|php)$">
Header set Cache-Control "private, must-revalidate"
</filesMatch>
</ifModule>
# END Cache-Control Headers
I first had nothing, then I tried with just the 'expires caching', first piece of code and after that didn't change a thing in the re-tested results, I added the second pair of code -> cache control headers. Strangely, I'm still scoring the same.
I'm on the verge of thinking my HTaccess file looks alright, but there is a problem on perhaps my server.. Or well, I just don't know. You guys probably do!
My .htaccess file is in the same folder as the index.html and assets folders are located.
The file structure looks like this:
/public_html/domain/company_name/website/.htaccess - For the .htaccess file
/public_html/domain/company_name/website/index.html - For the index.html file
THIS URL will link to the index.html file above.
When writing the title, I saw numbers of other related topics, however, most of them didn't work.
Where many related topics posted something about a corrupted or interfering file in the /etc/.. I don't have a /etc/ folder, so that couldn't be it.
Ok, so I found the problem! For anyone who can't find why it ain't working for them, try this!
My problem was that mod_expires wasn't active.
Create a php file and paste in the following code
<?php
print_r(apache_get_modules());
?>
And see if mod_expires is active. If it isn't showing, try this tutorial to active mod_expires. Then edit your htaccess file again and you'll probably see it's working!