【问题标题】:.htaccess <filesMatch> only if host name matches?.htaccess <filesMatch> 仅当主机名匹配时?
【发布时间】:2014-04-20 19:17:53
【问题描述】:

我刚刚使用与生产环境中相同的代码将本地环境设置为带有 ubuntu32 的 vagrant 虚拟机,

问题是我在 .htaccess 文件中的所有规则都出现内部服务器错误

所以我开始删除单独的代码块,这就是问题所在:

# 1 weeks
<FilesMatch "\.(js|css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 1 weeks
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 1 MIN
<FilesMatch "\.(html|htm|php)$">
Header set Cache-Control "max-age=60, private, proxy-revalidate"
</FilesMatch>

问题是我想对所有环境使用完全相同的代码,有没有办法我只能在localhost 中不包含&lt;filesMatch&gt; 的那个块?

我找到了这个answer,但它只是指一个页面,而不是主机名。

【问题讨论】:

    标签: apache .htaccess localhost setenv


    【解决方案1】:

    你可能会这样做:

    SetEnvIf Host ^ NON_LOCAL
    SetEnvIf Host localhost !NON_LOCAL
    
    <FilesMatch "\.(js|css)$">
    Header set Cache-Control "max-age=604800, public" env=NON_LOCAL
    </FilesMatch>
    
    # 1 weeks
    <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=604800, public" env=NON_LOCAL
    </FilesMatch>
    
    # 1 MIN
    <FilesMatch "\.(html|htm|php)$">
    Header set Cache-Control "max-age=60, private, proxy-revalidate" env=NON_LOCAL
    </FilesMatch>
    

    【讨论】:

      猜你喜欢
      • 2011-09-26
      • 1970-01-01
      • 1970-01-01
      • 2019-07-21
      • 1970-01-01
      • 1970-01-01
      • 2021-03-13
      • 2015-09-20
      • 2016-12-27
      相关资源
      最近更新 更多