简体   繁体   English

即使设置了正确的缓存控制标头,为什么 Chrome 缓存 302 重定向?

[英]Why is Chrome caching 302 redirect even though proper cache-control headers are set?

I have custom page in Drupal 7 to handle 403 and 404 requests which redirects the user to my applications homepage.我在 Drupal 7 中有自定义页面来处理 403 和 404 请求,这些请求将用户重定向到我的应用程序主页。 I have set an error message to display after redirection.我设置了重定向后显示的错误消息。 The issue is that when an invalid URL is requested frequently, the error is not displayed/set because chrome is caching my redirect page.问题是,当频繁请求无效 URL 时,不会显示/设置错误,因为 chrome 正在缓存我的重定向页面。 When I try this on other browsers the error message is set on every request.当我在其他浏览器上尝试此操作时,每个请求都会设置错误消息。 To counter this I have set the Cache-Control header to 'no-cache, no-store, max-age=0, must-revalidate, post-check=0, pre-check=0' and Expires header to 0. I also tried setting the above headers in my htaccess file.为了解决这个问题,我将 Cache-Control 标头设置为“no-cache, no-store, max-age=0, must-revalidate, post-check=0, pre-check=0”,并将 Expires 标头设置为 0。我还尝试在我的 htaccess 文件中设置上述标题。 Still the issue persists.问题仍然存在。 I need a solution such that I can stop my redirect caching我需要一个解决方案,以便我可以停止重定向缓存

I assume that basically you want to display error whenever 403 and 404 request made to your application and due to caching you are unable to display error message all the time.我假设基本上您希望在向您的应用程序发出 403 和 404 请求时显示错误,并且由于缓存,您无法一直显示错误消息。

What you can do is when first time 403/404 request made to your app, store it to sessions and next time again same request made to your app then you can find it in session variable.您可以做的是当第一次向您的应用程序发出 403/404 请求时,将其存储到会话中,下次再次向您的应用程序发出相同请求时,您可以在会话变量中找到它。 if found then display errors.如果找到则显示错误。

The above solution does not deal with the cache but might help you to achieve your requirements.上述解决方案不处理缓存,但可能会帮助您实现您的要求。

Thanks :)谢谢 :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么即使缓存控制 header 存在,Chrome 也不缓存响应? - Why isn't Chrome caching responses, even when cache-control header is present? Django Cache-control标头:Chrome为什么不缓存此资源? - Django Cache-control header: Why isn't Chrome caching this resource? Chrome甚至使用Cache-Control来缓存service-worker.js:不存储,不缓存最大年龄:0 - Chrome is caching service-worker.js even with Cache-Control: no-store, no-cache Max-Age: 0 即使使用HTTP无缓存标头,Chrome也会进行缓存 - Chrome is caching even with HTTP no-cache headers Chrome和Safari缓存302重定向 - Chrome and Safari caching 302 redirect 浏览器不是在HTTPS中缓存图像(HTTP工作正常)。 即使使用Cache-Control:public - Browser is not caching images in HTTPS (HTTP works fine). Even with Cache-Control: public Chrome 正在发送 Cache-control:no-cache 标头 - Chrome is sending Cache-control:no-cache header 即使没有缓存控制 header,响应也会被缓存吗? - Do responses get cached even if there is no cache-control header? Cache-Control标头的HTML元标记不适用于chrome - HTML meta tag for Cache-Control header does not work with chrome Chrome 忽略 Cache-Control no-store 指令? - Chrome Ignoring Cache-Control no-store directive?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM