Set-Cookie和Expires标头不同

时间:2009-10-05 20:19:02

标签: apache .htaccess yslow mod-expires

我正在尝试按照YSlow的建议为图像启用Expires标头。我确定我之前有这个工作,但现在当我检查YSlow它说它们没有被缓存。

对于我的.htaccess,我试过了:

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

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为我的一张图片输出以下内容:

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

Set-Cookie部分看起来正确但Expires标头不正确。如何正确设置过期,为什么它们不同?我已经仔细检查过mod_expires和mod_headers是否已启用。

1 个答案:

答案 0 :(得分:1)

从Set-Cookie标头看,这看起来像是php会话的一部分。 php会在session_start()之后自动禁用缓存。

您可以通过更改php.ini中的session.cache_limiter来修改此行为。有关各种设置,请参阅the PHP manual page

或者,您可以尝试使用“set”而不是“append”来覆盖.htaccess中的标题。