【问题标题】:how to add header expire in cakephp 2如何在 cakephp 2 中添加标头过期
【发布时间】:2013-07-30 09:19:47
【问题描述】:

我正在做一个 cakephp2 网站速度改进。

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

但在 cakephp 中,我必须将代码放在 htaccess 中。

请推荐任何不错的 htaccess 代码。

我试过了

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

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

还有一件事,如果有任何其他技巧可以提高性能,请建议我。

【问题讨论】:

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


    【解决方案1】:

    将以下代码添加到 .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

    【讨论】:

      【解决方案2】:

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

      <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查看详细信息

      希望这对你有帮助

      【讨论】:

      猜你喜欢
      • 2016-12-06
      • 2014-07-19
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      • 2018-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多