-->

mod_headers中htaccess的毫无缓存(htaccess mod_headers for

2019-09-16 10:12发布

我们有一个应用程序,允许用户添加/编辑/替换/删除内容(文字,图片,SWF文件,MP3音乐等)。 我们希望管理员总是使用no-cache标题有最新更新的文件,当用户运行应用程序时,一切变得/使用缓存。

我已经调查方案,并使用HTML元标签,如曾尝试:

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

但是,这似乎并没有得到很好的解决,因为这发生在创建头之后,不改变媒体(图像,SWF文件,MP3音乐等)的头。

我想使用Apache设置页眉和跨越这个代码来到这个网站 :

<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 VS run.jsp),所以我们不能按文件类型匹配它因为大多数的文件是相同的。

有没有人有这种类型的场景好的解决办法?

谢谢。

编辑:

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上。

Answer 1:

的组合SetEnvIfHeader可能做的伎俩:

# 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


Answer 2:

你可以设置你的Java servlet相应的头文件。 mod_headers中的Apache大多应该为静态资源,通过Apache的管理工作。 虽然这是由应用程序服务器提供的一切都在AS侧管理。

通常情况下,你可以使用过滤器用于此目的。 下面是一个例子: http://www.tidytutorials.com/2009/11/adding-headers-to-requests-in-filters.html



文章来源: htaccess mod_headers for no-caching