如何使用.htaccess禁用代理caching

我有一个问题,企业代理服务器为不同的login用户提供页面。 我想我可以通过禁用代理caching来解决这个问题。 本页build议在htaccess中包含以下代码片段:

ExpiresDefault A0 Header set Cache-Control "no-store, no-cache, must-revalidate, max-age=0" Header set Pragma "no-cache" 

据我所知(通过谷歌search),过期头只能通过代理读取,所以我可能也只是使用“头集过期0”?

我想这也会阻止caching样式表,图像和其他资产(尽pipe只能通过代理,而不是浏览器)?

处理这个问题的最好方法是什么? 我正在运行PHP,并且可以通过PHP轻松修改头文件,如果推荐的话。

我无法访问代理服务器进行testing。

从http 1.1规范( RFC 2616 )第14.9.1章

 private Indicates that all or part of the response message is intended for a single user and MUST NOT be cached by a shared cache. This allows an origin server to state that the specified parts of the 

标题集高速缓存控制“私人,…”是诀窍。

不需要Expires标题。 缓存控制:max-age覆盖Expires字段。 请参阅RFC部分:14.21

您应根据您提供的内容发送不同的缓存标头。

以下示例适用于在/ static中提供静态内容的网站,并且会为登录的用户更改内容。 登录的用户通过会话cookie的存在来标识:MYSESSID。

  • 默认允许5分钟的公共缓存
  • 在静态文件上允许365天的公共缓存
  • 允许登录用户进行5分钟的私人缓存
  • 拒绝缓存在/动态/ *

 RewriteEngine On # Flag files in /static as STATIC RewriteRule ^static - [E=STATIC:1] # Flag requests by logged in users as PRIVATE # Users are identified by presence of MYSESSID cookie # Ignores files in: /static RewriteCond %{HTTP_COOKIE} MYSESSID RewriteCond %{REQUEST_URI} !^/static RewriteRule ^ - [E=PRIVATE:1] # Tell proxy servers that contents not in /static vary based on the given cookies RewriteCond %{REQUEST_URI} !^/static RewriteRule ^ - [E=VARY:1] # Flag requests to /dynamic as NO_CACHE RewriteRule ^dynamic - [E=NO_CACHE:1] ## Default Cache-Control # Per default, any content is public and 5min cacheable Header set Cache-Control "public, max-age=300" ## Static Files # Static files are public and 365d cacheable. Header set Cache-Control "public, max-age=31536000" env=STATIC # Reset age, indicates objects as fresh Header set Age 0 env=STATIC ## Private responses # private. Allow 5min caching Header set Cache-Control "private, max-age=300" env=PRIVATE ## Deny caching Header set Cache-Control "private, max-age=0, no-cache, no-store, must-revalidate" env=NO_CACHE ## Vary rules Header append Vary: Cookie env=VARY 

使用:

ExpiresActive On

现在过期默认

标题集Cache-Control“no-cache,no-store,must-revalidate,max-age = 0,proxy-revalidate,no-transform”

头文件集Pragma“no-cache”