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

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

问题描述

httpd.conf中,最后一行是:

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指令.

该站点位于运行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天全站免登陆