htaccess mod_headers 用于无缓存

2024-04-07

我们有一个应用程序,允许用户添加/编辑/替换/删除内容(文本、图像、swf、mp3 等)。我们希望管理员通过使用无缓存标头始终拥有最新更新的文件,并且当用户运行应用程序时,所有内容都会获取/使用缓存。

我研究了解决方案并尝试使用 html 元标记,例如:

<meta http-equiv="expires" content="0" />
<meta http-equiv="cache-control" content="no-cache, no-store" />
<meta http-equiv="pragma" content="no-cache" />

但这似乎不是一个好的解决方案,因为这种情况发生在创建标头之后,并且不会更改媒体(图像、swfs、mp3 等)标头。

我想使用 apache 设置标头,并遇到了这段代码这个网站 http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html:

<filesMatch "\.(html|htm|js|css)$">
FileETag None
<ifModule mod_headers.c>
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
</ifModule>
</filesMatch>

这似乎是一个很好的解决方案,但是当我们需要缓存它和不应该缓存它时之间唯一真正的区别是 URL(preview.jsp 与 run.jsp),因此我们无法按文件类型匹配它因为大多数文件都是相同的。

对于这种情况,有人有好的解决方案吗?

谢谢。

EDIT:

Preview.jsp和run.jsp基本上是相同的,只是jsp和js处理不同。他们通过 iframe 读取相同的内容和媒体。例如,它们各自看起来像:

<%
//Some JSP
%>
/* HTML Headers, JS, ETC */
<iframe id="contentFrame" seamless="1" src="http://somedomain.com/template.html"></iframe>
/* End HTML */

Preview.jsp 和 run.jsp 出现在同一目录中并使用所有相同的资源。我正在寻找一种解决方案,让 Preview.jsp 不缓存任何内容,而 run.jsp 来缓存内容。

服务器使用 Apache Tomcat 设置。


的组合SetEnvIf http://httpd.apache.org/docs/2.2/mod/mod_setenvif.html#setenvif and Header http://httpd.apache.org/docs/2.2/mod/mod_headers.html#header可能会解决这个问题:

# Image, CSS and JavaScript requests normally contain the Referer header
# which tells apache which page is requesting the resource
# Use SetEnvIf directive to set a flag for internal uses

SetEnvIf Referer preview\.jsp force_no_cache

# Header directive optionally accepts env= argument
# If present, the directive is fired if the flag is set

Header unset ETag env=force_no_cache

# repeat for other headers
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

htaccess mod_headers 用于无缓存 的相关文章

随机推荐