.htaccess - PHP : header expires not working

标签 .htaccess mod-expires response-headers expires-header

我的PHP代码:

$expires_date = date('D, j F Y H:i:s', strtotime('now + 10 years')) . ' GMT';           
header("Expires: $expires_date");
header('Content-type: text/javascript');

echo 'hello world';

当我检查响应头时,我看到:
Expires:Thu, 01 Jan 1970 00:00:00 GMT
我究竟做错了什么?

更新:

只是在试验,但似乎我什至无法通过 header_remove('Expires'); 取消设置过期.我仍然看到 1970 年的日期。

更新:

我的响应头:
Cache-Control:private
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:74
Content-Type:text/javascript
Date:Wed, 17 Oct 2012 22:40:45 GMT
Expires:Thu, 01 Jan 1970 00:00:00 GMT
Keep-Alive:timeout=5, max=98
Server:Apache/2.2.21 (Win32) PHP/5.3.9
Vary:Accept-Encoding
X-Powered-By:PHP/5.3.9

最佳答案

查看您的 htaccess 文件:

<FilesMatch "\.(htm|html|php)$">
        Header set Expires "Thu, 01 Jan 1970 00:00:00 GMT"

        # TODO: Google.com's setting are the following
        # Expires -1
        # Cache-Control private, max-age=0
</FilesMatch>

它看起来像你的 FilesMatch .php正在覆盖 .htaccess Content-Type:text/javascript规则和 PHP 过期 header ,因为脚本是 .php 文件。

注释掉这个标题在你的 .htaccess 中过期,看看 PHP 标题 +10 年过期是否仍然给出 1/1/1970 日期

关于.htaccess - PHP : header expires not working,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12935560/

相关文章:

php - Codeigniter 3.1.6 - 如何从 url 中删除 index.php

apache - 如何检查 apache 中启用的 mod_headers 和 mod_expires 模块

caching - 停止浏览器对应保留缓存的图像发出 HTTP 请求 - mod_expires

angularjs - 如何使用 $resource 读取响应 header ?

php - 如何防止子域名被重定向到https

.htaccess - 向现有 .htaccess 添加选项

php - Laravel 与子域共享主机

apache - 将 ExpiresDefault 添加到 .htaccess 文件

java - tomcat的默认缓存 header ?

django - 删除 Django Rest Framework 响应中的 header