【问题标题】:How to set expiry headers using htaccess for Yii cached files如何使用 htaccess 为 Yii 缓存文件设置过期标头
【发布时间】:2018-03-28 04:57:58
【问题描述】:

我在 Yii 框架中有一个网站,Yii 版本是 1.1.16

我在我的 htaccess 中应用了以下代码

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access 1 month"
</IfModule>
## EXPIRES CACHING ##

但是当我使用谷歌页面洞察检查我的网站时,它说

https://www.example.com/assets/593f25af/images/dropdown.png(未指定过期时间)

为了管理缓存,我在 config 文件夹下的 main.php 文件中添加了这段代码:

'cache' => array(
       'class' => 'CApcCache',
 ),

你们能告诉我,我做错了什么,所以过期标头不适用于这些缓存文件。

请帮帮我!

【问题讨论】:

  • 添加了一个答案,看看它是否对你有帮助

标签: php .htaccess caching yii1.x


【解决方案1】:

您能否尝试将您的配置替换为您的 .htaccess

#
# configure mod_expires
#
# URL: http://httpd.apache.org/docs/2.2/mod/mod_expires.html
#
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault "access plus 1 seconds"
    ExpiresByType image/x-icon "access plus 2692000 seconds"
    ExpiresByType image/jpeg "access plus 2692000 seconds"
    ExpiresByType image/vnd.microsoft.icon "access plus 2692000 seconds"
    ExpiresByType image/png "access plus 2692000 seconds"
    ExpiresByType image/gif "access plus 2692000 seconds"
    ExpiresByType application/x-shockwave-flash "access plus 2692000 seconds"
    ExpiresByType text/css "access plus 2692000 seconds"
    ExpiresByType text/javascript "access plus 2692000 seconds"
    ExpiresByType application/x-javascript "access plus 2692000 seconds"
    ExpiresByType text/html "access plus 600 seconds"
    ExpiresByType application/xhtml+xml "access plus 600 seconds"
</IfModule>


#
# configure mod_headers
#
# URL: http://httpd.apache.org/docs/2.2/mod/mod_headers.html
#
<IfModule mod_headers.c>
    <FilesMatch "\\.(ico|jpe?g|png|gif|swf|css|js)$">
        Header set Cache-Control "max-age=2692000, public"
    </FilesMatch>
    <FilesMatch "\\.(x?html?|php)$">
        Header set Cache-Control "max-age=600, private, must-revalidate"
    </FilesMatch>
    Header unset ETag
    Header unset Last-Modified
</IfModule>

【讨论】:

    【解决方案2】:

    感谢大家的回答,但后来我意识到这是服务器级别的问题。我的 Plesk 托管出现了一些问题,我联系了托管人员,他们修复了它,现在相同的 .htaccess 代码正在运行。

    【讨论】:

      猜你喜欢
      • 2023-03-15
      • 1970-01-01
      • 2012-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-19
      • 1970-01-01
      • 2019-04-08
      相关资源
      最近更新 更多