Set-Cookie 和 Expires 标头不同
我正在尝试按照 YSlow 的建议启用图像的过期标头。我确定我以前有这个工作,但现在当我检查 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 是否已启用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从
Set-Cookie
标头来看,这看起来像是 PHP 会话的一部分。 PHP 在session_start()
之后自动禁用缓存。您可以通过更改 php.ini 中的
session.cache_limiter
来修改此行为。请参阅 PHP 手册页各种设置。或者,您可以尝试使用
set
而不是append
来覆盖 .htaccess 中的标头。From the
Set-Cookie
header, it looks like this is part of a PHP session. PHP automatically disables caching after asession_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 ofappend
to override the headers in your .htaccess.