【问题标题】:document.referrer is empty between two https两个 https 之间的 document.referrer 为空
【发布时间】:2019-10-24 20:42:42
【问题描述】:

从两个https网站重定向时Referer为空

http://site0.gb => 302 redirect => https://site1.co => 302 redirect => https://site2.com => document.referrer is empty

所有网站的标题设置都是Referrer-Policy: no-referrer-when-downgrade

这很奇怪,因为Referrer-Policy

no-referrer-when-downgrade : https://example.com/page.html -> https://mozilla.org 

document.referrer 是https://example.com/page.html

如何使它工作。我可以得到https://site1.co 的document.referrer 吗?以及空referer的原因是什么?

【问题讨论】:

  • 请注意,document.referrer 不一定与 Referer 标头相同(这是 Referrer-Policy 控制的内容)。另外,请注意 th document.referrer 页面上的文本:“如果用户直接导航到该页面(不是通过链接,而是例如通过使用书签),则该值是一个空字符串”。我希望 302 重定向不是“直接导航到页面”。
  • 是的,我知道。我还在其他域上测试过这种情况,例如 http://domain1.comhttps://domain2.com 与 302 重定向,它工作正常。 document.referrer 正在此域之间发送

标签: javascript url https referrer referer


【解决方案1】:

这种行为正是使用过多的 302 重定向而不是使用类似 mod rewrite 或其他服务器端系统来转发网页被认为是不好的做法的确切原因。

您还可以使用服务器配置文件在某些​​服务器上包含原始引荐来源网址。

您最好在页面加载之前使用 PHP 设置标题,或者如果没有使用 javascript,则使用旧的引用者向新 URL 发出 POST 请求。

【讨论】:

  • 谢谢。也许这个问题与服务器属性有关。因为我在搜索后在 google 上看到了 https 域之间的重定向。它看起来不错。无论如何感谢您的回答。
猜你喜欢
  • 1970-01-01
  • 2013-07-16
  • 2014-04-23
  • 1970-01-01
  • 2013-01-05
  • 2021-08-21
  • 2015-02-28
  • 2016-01-07
  • 1970-01-01
相关资源
最近更新 更多