【问题标题】:nginx Clear 301 Permanent from clients browser cachenginx 从客户端浏览器缓存中清除 301 Permanent
【发布时间】:2017-02-04 04:17:54
【问题描述】:

我在 Nginx 中愚蠢地使用 301 而不是 302 进行特定重定向

location /somewhere/ {
  return 301 /somewhere/neat/;
}

但现在我也需要更改重定向的位置:

location /somewhere/ {
  # 302 now, lets not make the same mistake again!
  return 302 /somewhere/else/entirely/;
}

如果我以隐身模式查看 URL 或破坏我的浏览器重定向缓存,我当然可以看到这种变化,但许多用户如果不自己做同样的事情就看不到它。即使我们可以可靠地指示我们的客户破坏他们的缓存,我们也只能到达其中的一小部分,而其余的都将保留旧内容。

【问题讨论】:

  • 对 w/ngnix 和 ssl 没有超级经验(所以不确定这个答案是否完全适用,但是)有同样的问题,我只需要清除浏览器上的缓存来解决缓存问题。 (就我而言,我怀疑是由于当天早些时候测试了重定向(使用旧站点)。

标签: redirect caching nginx browser-cache http-status-code-301


【解决方案1】:

你说的是缓存破坏,我也有同样的问题。您需要做的所有事情(如果我理解正确的话)就是将查询字符串参数强制放在 url 的末尾,这会有效地强制客户端浏览器刷新以获取任何“新”内容。

如果该查询字符串不存在,则一种可能的解决方法是将查询字符串附加到 URL 的末尾。

在您的情况下,您可能可以使用重写来“修复”错误的 url,并缓存破坏原始 url 重定向:

# Fix the incorrect url
location /somewhere/neat/ {
  rewrite ^(.*)$ /somewhere/$1?cb=12345 last;
}

# Handle the new redirect
location /somewhere/ {
  return 302 /somewhere/else/entirely/;
}

cb=12345 可以是任何你想要的,只要它只是一个查询字符串

这种方法的唯一问题是如果您的位置 /somewhere/neat 仍然需要是一个活动页面,因为这将有效地迫使它总是返回到 /somewhere

【讨论】:

    猜你喜欢
    • 2018-04-27
    • 2012-01-10
    • 1970-01-01
    • 2021-02-10
    • 2019-07-12
    • 2021-01-25
    • 2011-02-04
    • 1970-01-01
    • 2020-10-26
    相关资源
    最近更新 更多