【问题标题】:sending cache-control headers not working in Codeigniter发送缓存控制标头在 Codeigniter 中不起作用
【发布时间】:2012-03-21 00:54:28
【问题描述】:

我可能遗漏了一些明显的东西,但是当我要求它时,我的 Codeigniter 应用程序没有发送标头。 所以在任何控制器或扩展的 MY_Controller 中:

$this->output->set_header("Last-Modified: " . gmdate( "D, j M Y H:i:s" ) . " GMT");
$this->output->set_header("Expires: " . gmdate( "D, j M Y H:i:s", time() ) . " GMT");
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate");
$this->output->set_header("Cache-Control: post-check=0, pre-check=0");
$this->output->set_header("Pragma: no-cache");
$this->output->set_header("Steve: it aint working you know");

我得到的标题是:

HTTP/1.1 200 OK
Date: Mon, 19 Mar 2012 18:03:06 GMT
Server: Apache/2.2.20 (Ubuntu)
X-Powered-By: PHP/5.3.6-13ubuntu3.6
Last-Modified: Mon, 19 Mar 2012 18:03:06 GMT
Expires: Sat, 01 Jan 2000 00:00:01 GMT
Cache-Control: post-check=0, pre-check=0, max-age=0
Pragma: no-cache
Steve: it aint working you know
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Length: 10780
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html

所以我知道它正在从 Steve: 标头发送标头,但它没有发送我的 Cache-Control 设置。如果我注释掉 Cache-Control 设置,它仍然显示相同的值。

这可能在哪里被覆盖?是 Codeigniter、PHP 还是 Apache?

【问题讨论】:

    标签: php http codeigniter


    【解决方案1】:

    我会检查您的 Apache 配置,特别是如何配置 mod_expiresHeader Directive

    请注意,“标题在内容处理程序和输出过滤器运行后立即修改,允许修改传出标题。”所以 Apache 可能会被设置为修改你在 PHP 中设置的标头。

    我不是 Apache 专家,但这是我必须解决的类似问题。

    【讨论】:

      【解决方案2】:

      我采取的步骤: 将以下内容添加到我的 .htaccess 文件中。

      <IfModule mod_headers.c>
      Header add Cache-Control:  "no-store, no-cache, must-revalidate"
      </IfModule>
      

          sudo a2enmod headers
          sudo service apache2 restart
      

      【讨论】:

        猜你喜欢
        • 2019-12-22
        • 2017-10-19
        • 2011-05-08
        • 2020-07-17
        • 2011-01-13
        • 2020-10-03
        • 1970-01-01
        • 2016-04-26
        • 1970-01-01
        相关资源
        最近更新 更多