标题过期不起作用 [英] Header Expires not working

查看:32
本文介绍了标题过期不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

httpd.conf 中的最后几行是:

In httpd.conf the last lines are:

ExpiresActive On
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
    ExpiresDefault "access plus 3 days"
</FilesMatch>

当我运行 YSlow 时,它说我的所有 CSS 文件(和其他文件)都没有设置过期时间.CSS 文件位于子目录中,但我相信 "\." 应该匹配所有文件,无论子目录如何.

When I run YSlow it says all my CSS files (and others) do not have expiration set. The CSS files are in subdirectories but I believe "\." should match all files regardless of subdirectory.

Apache 是为虚拟主机设置的,但上述指令位于 httpd.conf 最底部的 vhosts 部分之外.

Apache is set up for virtual hosts, but the above directives are outside of vhosts section at the very bottom of httpd.conf.

.conf 文件中有一个用于 LoadModule expires_module modules/mod_expires.so 的指令.

There is a directive for LoadModule expires_module modules/mod_expires.so in the .conf file.

该站点位于运行 AWS Linux 和 Apache2 的 AWS 上.在检查它是否有效之前,我重新启动了 apache.

The site is on AWS running AWS Linux and Apache2. I restarted apache before checking if it worked.

推荐答案

回答你的问题,这在我的 httpd.conf 中对我有用:

In answer to your question, this works for me in my httpd.conf:

LoadModule expires_module /usr/lib/apache2/modules/mod_expires.so
ExpiresActive On

<filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresDefault "access plus 3 days"
</filesMatch>

这里有一些事情可以尝试:

Here are a few things to try:

1) 确保 mod_expires.so 是您认为的位置.您可以通过在终端中使用它来查看包含哪些模块:apache2 -M.

1) Make sure mod_expires.so is where you think it is. You can see what modules are being included by using this in your terminal: apache2 -M.

2) 确保您的指令适用于您感兴趣的文件(即不会被.htaccess 文件覆盖)

2) Make sure your directives apply to the files you're interested in (i.e. not getting overwritten by a .htaccess file somewhere farther down the line)

3) 确保 LoadModule 指令在你的 httpd.conf 文件中

3) Make sure the LoadModule directive is in your httpd.conf file

4) 在您的 FilesMatch 正则表达式中,您应该使用反斜杠对点进行转义,否则您将匹配任何字符.不是什么大问题,但您最终会将规则应用于非静态页面,例如 "site.com/politico"(注意 ico 结尾).

4) In your FilesMatch regex, you should escape the dot with a backslash otherwise you're matching any character. Not a big issue, but you'd end up applying the rule to non-static pages like "site.com/politico" (note the ico ending) for example.

这篇关于标题过期不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆