gpt4 book ai didi

使用 HTTP->HTTPS Apache 重定向时,Javascript `document.referrer` 消失

转载 作者:行者123 更新时间:2023-12-03 18:58:01 31 4
gpt4 key购买 nike

我将所有网站从 HTTP 重定向到 HTTPS:

<VirtualHost *:80>
ServerName example.com
RewriteEngine on
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>

<VirtualHost *:443>
ServerName example.com
DocumentRoot /www/example.com
SSLEngine on
...
</VirtualHost>
我注意到,从网站导航时 anothersite.com
  • 点击链接到 https://example.com , Javascript 的 document.referrer工作并给予anothersite.com
  • 点击链接到 http://example.com , Javascript 的 document.referrer 为空 !

  • 如何预防document.referrer通过 Apache 使用 HTTP->HTTPS 重定向时消失?
    或者我应该使用另一种方法进行自动 HTTP->HTTPS 重定向以保持 referrer ?

    最佳答案

    this answer 中所述,由浏览器在重定向后将引用者发回。显然,事实并非如此。
    但是,您可以像这样编写规则并从查询中读取引荐来源网址(如果 header 中不存在引荐来源网址)。

      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}?referrer=%{HTTP_REFERER}
    请注意,用户总是可以欺骗引荐来源网址。但是这种方法会更容易欺骗它。根据您的用例,此解决方案可能对您来说是一个安全问题。
    更正
    根据 this answer当用户:

    switches from a https URL to a http URL.


    HTTP specs 中的其他信息.

    关于使用 HTTP->HTTPS Apache 重定向时,Javascript `document.referrer` 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65405413/

    31 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com