Reputation: 7092
I tried a couple of approaches to get images and other resources to have an expiration date, but none seem to work accourding to http://www.webpagetest.org/
I also installed W3 plugin, still the tool reports the images do not have expires headers set.
I also included the following code in my htaccess:
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A300
ExpiresByType application/x-javascript A3600
ExpiresByType text/css A3600
ExpiresByType image/gif A3600
ExpiresByType image/png A3600
ExpiresByType image/jpeg A3600
ExpiresByType text/plain A300
ExpiresByType application/x-shockwave-flash A3600
ExpiresByType video/x-flv A3600
ExpiresByType application/pdf A3600
ExpiresByType text/html A300
</IfModule>
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
This seems to be a common problem, and I have seen many questions about this, but couldn't find an answer.
Is the problem in the testing tool or on my server? How can I find out?
Upvotes: 6
Views: 14348
Reputation: 148
We were trying to get a wrong result. i was searching for a solution too but what i found after reading the GTMetrix test result with those (expire header) code and without them:
Upvotes: 0
Reputation: 3267
The answer for me was enable expires module.
a2enmod expires
systemctl restart apache2
Answer by: Southparkfan in https://www.digitalocean.com/community/questions/how-to-setup-expire-headers-on-apache
So this code will work in apache server conf
<IfModule mod_expires.c>
ExpiresActive on
ExpiresDefault "access plus 1 month"
ExpiresByType text/html "access plus 15 days"
ExpiresByType image/gif "access plus 1 months"
ExpiresByType image/jpg "access plus 1 months"
ExpiresByType image/jpeg "access plus 1 months"
ExpiresByType image/png "access plus 1 months"
ExpiresByType text/js "access plus 1 months"
ExpiresByType text/javascript "access plus 1 months"
ExpiresByType application/vnd.ms-fontobject "access plus 1 year"
ExpiresByType font/ttf "access plus 1 year"
ExpiresByType font/otf "access plus 1 year"
ExpiresByType font/woff "access plus 1 year"
ExpiresByType font/woff2 "access plus 1 year"
ExpiresByType image/svg+xml "access plus 1 year"
</IfModule>
Hope that helps
Upvotes: 2
Reputation: 174
I had the same kind of problem. It seems (some) validators, like YSlow, don't succeed until the expires dates are on value 31536000
.
Here's a full W3 Total Cache htaccess: http://pastebin.com/wegK3jD6.
It worked for me, you might as well give it a shot.
Note that the pastebin doesn't contain the WordPress htaccess content
Upvotes: 5