Javascript error int 未能设置引用策略
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39943549/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
error int the Failed to set referrer policy
提问by Holly
I'm getting the following error in my chrome console for a Wordpress site I'm working on.
对于我正在处理的 Wordpress 站点,我在 chrome 控制台中收到以下错误。
Failed to set referrer policy: The value 'http://example.com/comic/' is not one of 'always', 'default', 'never', 'no-referrer', 'no-referrer-when-downgrade', 'origin', 'origin-when-crossorigin', or 'unsafe-url'. The referrer policy has been left unchanged.
无法设置引用策略:值“ http://example.com/comic/”不是“always”、“default”、“never”、“no-referrer”、“no-referrer-when-downgrade”之一'、'origin'、'origin-when-crossorigin' 或 'unsafe-url'。推荐人政策保持不变。
It's reffereing to this line in the <head>
of the HTML document...
它是指<head>
HTML 文档中的这一行...
<meta name="Referrer" content="http://example.com/comic/" />
I'm vieing the page over http
, not https
.
我正在浏览页面http
,而不是https
。
What is causing this issue and how can I fix it?
是什么导致了这个问题,我该如何解决?
回答by Deepesh Thapa
Go into your .htaccess file and change the following:
进入您的 .htaccess 文件并更改以下内容:
Header set Referrer-Policy ""
to
到
Header set Referrer-Policy "origin"
That should fix the issue.
那应该可以解决问题。
The reason is more than likely because you don't have correct permissions on your .htaccess file that allows w3tc to make the changes it needs to.
原因很可能是因为您对 .htaccess 文件没有正确的权限,允许 w3tc 进行所需的更改。
回答by maioman
Here 's the definition taken from the specs:
这是从规范中获取的定义:
A referrer policy modifies the algorithm used to populate the Referer header when fetching subresources, prefetching, or performing navigations. Every environment settings object has an algorithm for obtaining a referrer policy, which is used by default for all requests with that environment settings object as their request client.
引用策略修改用于在获取子资源、预获取或执行导航时填充引用标头的算法。每个环境设置对象都有一个用于获取引用策略的算法,默认情况下,该算法用于将该环境设置对象作为其请求客户端的所有请求。
Therefore Referral policy deals with what information (related to the url) the browser ships to a server to retrieve an external resource.
因此,引用策略处理浏览器发送到服务器以检索外部资源的信息(与 url 相关)。
The options for the content
attribute listed in the specs are :
content
规范中列出的属性选项是:
no-referrer
which specifies that no referrer information is to be sent along with requests made from a particular request client to any origin. The header will be omitted entirely.no-referrer-when-downgrade
doesn't send Referrer header to non priori authenticated url(if an https url links to an http url no header is sent)same-origin
policy specifies that a full URL, stripped for use as a referrer, is sent as referrer information when making same-origin requests from a particular request client. while Cross-origin requests won't contain referrer information.origin
sends the scheme, host, and port (basically, the subdomain) stripped of the full URL as a referrer, i.e. https://moz.com/example.htmlwould simply send https://moz.comfor all.origin-when-cross-origin
sends the format described inorigin
to cross-origin, while a full stripped URL is sent to same origin requests.unsafe-url
policy specifies that a full URL, stripped for use as a referrer, is sent along with both cross-origin requests and same-origin requests made from a particular request client.
it's unsafe because it will leak origins and paths from TLS-protected resources to insecure origins.The empty string "" corresponds to no referrer policy, causing a fallback to a referrer policy defined elsewhere, or in the case where no such higher-level policy is available, defaulting to
no-referrer-when-downgrade
.always
behaves likeunsafe-url
.
no-referrer
它指定不会将引用信息与从特定请求客户端发出的请求一起发送到任何来源。标题将被完全省略。no-referrer-when-downgrade
不将 Referrer 标头发送到非先验验证的 url(如果 https url 链接到 http url,则不发送标头)same-origin
策略指定在从特定请求客户端发出同源请求时,将被剥离用作引用者的完整 URL 作为引用者信息发送。而跨域请求将不包含引用信息。origin
发送去除了完整 URL 的方案、主机和端口(基本上是子域)作为引用,即https://moz.com/example.html将简单地发送https://moz.com。origin-when-cross-origin
将 中描述的格式发送origin
到跨域,而完整的剥离 URL 被发送到相同的源请求。unsafe-url
策略指定一个完整的 URL,被剥离用作引用者,与来自特定请求客户端的跨域请求和同源请求一起发送。
它是不安全的,因为它会将来源和路径从受 TLS 保护的资源泄漏到不安全的来源。空字符串 "" 对应于没有引用策略,导致回退到其他地方定义的引用策略,或者在没有此类更高级别策略可用的情况下,默认为
no-referrer-when-downgrade
。always
表现得像unsafe-url
.
回答by fraweb
you can manually find and change as following in .htaccess file :
您可以在 .htaccess 文件中手动查找和更改如下:
<IfModule mod_headers.c>
Header set Referrer-Policy ""
</IfModule>
to
到
<IfModule mod_headers.c>
Header set Referrer-Policy "origin"
</IfModule>
回答by Nexus7_2012
Chrome Inspection Console showed me the same Error for my Wordpress sites which have W3 Total Cache installed. "Failed to set referrer policy: The value '' is not one of 'no-referrer', 'no-referrer- when-downgrade', 'origin', 'origin-when-cross-origin'"
Chrome 检查控制台为我安装了 W3 Total Cache 的 Wordpress 站点显示了相同的错误。“无法设置引用策略:值 '' 不是 'no-referrer'、'no-referrer-when-downgrade'、'origin'、'origin-when-cross-origin' 之一”
and I tried to update the .htaccess file as indicated in the above answer. This fixed the Chrome Inspection Console error but it returned a few moments later.
我尝试更新 .htaccess 文件,如上述答案所示。这修复了 Chrome 检查控制台错误,但它在几分钟后返回。
Checking the Dashboard of W3 Total Cache Performance ->Browser Cache-> Referrer Policy-> Directive, this entry was showing blank.
检查 W3 Total Cache Performance ->Browser Cache-> Referrer Policy-> Directive 的仪表板,此条目显示为空白。
Selecting 'origin' from the dropdown resulted in .htaccess being updated with the same value 'origin'
回答by Pr0methean
"Referer" as a header is spelled without the double R. Maybe with the double R, it's matching against a different header than the one you mean.
“Referer”作为标题拼写没有双 R。也许使用双 R,它匹配与您的意思不同的标题。