如何在cakephp 2中添加标头过期

时间:2013-07-30 09:19:48

标签: apache .htaccess cakephp cakephp-2.0 mod-expires

我正在开发cakephp2网站之一的速度提升。

现在我需要设置一些标头过期和缓存内容。

但是在cakephp中,htaccess我必须把我的代码。

请建议任何好的htaccess代码。

我试过了

#Expire Header
<FilesMatch "\.(ico|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 2 hours"
</FilesMatch>

但它不起作用,我也尝试了其他几个代码,但没有一个代码适用于我。是否有任何关键配置缺失?

如果还有其他任何提高性能的技巧,那么请建议我。

2 个答案:

答案 0 :(得分:2)

下面的

可以添加它来修改.htaccess文件夹中的app/webroot/.htacces文件而不受惩罚。

<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType application/x-javascript A8640000
    ExpiresByType text/javascript A8640000
    ExpiresByType text/css A8640000
    ExpiresByType image/png A8640000
</IfModule>

或者如果您还可以在cakephp.org

详细查看

希望这一定会帮到你

答案 1 :(得分:2)

将以下代码添加到.htaccess文件

# cache images/pdf docs for 10 days
<FilesMatch "\.(ico|pdf|jpg|jpeg|png|gif)$">
  Header set Cache-Control "max-age=864000, public, must-revalidate"
  Header unset Last-Modified
</FilesMatch>

# cache html/htm/xml/txt diles for 2 days
<FilesMatch "\.(html|htm|xml|txt|xsl)$">
  Header set Cache-Control "max-age=7200, must-revalidate"
</FilesMatch>

更多信息http://tutorialpedia.org/tutorials/Apache+enable+file+caching+with+htaccess.html