我可能遗漏了一些明显的东西,但我的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:标头发送标头,但它没有发送我的缓存控制设置。如果我注释掉"缓存控制"设置,它仍然显示相同的值。
这在哪里可以被覆盖?是Codeigniter、PHP还是Apache?
我会检查您的Apache配置,特别是mod_expires
和Header指令的配置方式。
请注意,"在内容处理程序和输出过滤器运行后,会修改标头,从而允许修改传出标头。"因此,Apache可能会被设置为修改您在PHP中设置的标头。
我不是Apache专家,但这是我必须解决的类似问题
我采取的步骤:将以下内容添加到我的.htaccess文件中。
<IfModule mod_headers.c>
Header add Cache-Control: "no-store, no-cache, must-revalidate"
</IfModule>
运行
sudo a2enmod headers
sudo service apache2 restart