views:

483

answers:

1

I'm trying to enable Expires headers for images as recommended by YSlow. I'm sure I had this working before but now when I check YSlow it says they are not being cached.

For my .htaccess, I have tried:

ExpiresActive on
ExpiresDefault A0
<FilesMatch "\.(gif|ico|jpg|png)$">
    ExpiresDefault A29030400
    Header append Cache-Control "public"
</FilesMatch>

and

ExpiresActive on
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 month"

http://www.seoconsultants.com/tools/headers.asp outputs the following for one of my images:

HTTP Status Code: HTTP/1.1 200 OK
Date: Mon, 05 Oct 2009 20:12:04 GMT
Server: Apache/2.0.63 (Unix) mod_ssl/2.0.63 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4 PHP/5.2.8
X-Powered-By: PHP/5.2.8
Set-Cookie: PHPSESSID=5d11f4d8aa37ceee6605786e59ff4f0f; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: lastlogin=1254773024; expires=Mon, 02-Nov-2009 20:12:04 GMT
Connection: close
Content-Type: image/jpeg

The Set-Cookie part looks correct but the Expires header is not. How do I set Expires correctly and why do they differ? I have double checked that mod_expires and mod_headers are enabled.

+1  A: 

From the Set-Cookie header, it looks like this is part of a php session. php automatically disables caching after a session_start().

You can modify this behavior by changing session.cache_limiter in your php.ini. See the PHP manual page for the various settings.

Alternatively, you could try using "set" instead of "append" to override the headers in your .htaccess.

ataylor
The site was using an in-house framework which stores everything outside the public_html directory and serves up images from PHP scripts. I moved the images to public_html/img and the .htaccess settings worked correctly.
Matt McCormick