• 请不要在回答技术问题时复制粘贴 AI 生成的内容
TypeErrorNone
V2EX  ›  程序员

http 除了 302,为什么 200 也可以实现浏览器跳转?

  •  
  •   TypeErrorNone · Apr 28, 2017 · 8419 views
    This topic created in 3502 days ago, the information mentioned may be changed or developed.

    例如知乎外链的跳转地址: https://link.zhihu.com/?target=https://www.baidu.com

    请问是怎么实现的? 这是 link.zhihu.com 的响应内容
    Supplement 1  ·  Apr 28, 2017
    谢谢各位,明白了哈哈哈
    支付宝红包口令
    深夜 v2ex
    19 replies  •  2017-04-28 18:10:44 +08:00
    TypeErrorNone
    TypeErrorNone
    OP
    Apr 28, 2017
    1
    gracece
    gracece
    Apr 28, 2017
    2
    ~ curl 'https://link.zhihu.com/?target=https://www.baidu.com'
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="shortcut icon" href="https://static.zhihu.com/static/favicon.ico" type="image/x-icon">
    <title>跳转中...</title>
    </head>
    <script>
    var URI = "https%3A%2F%2Fwww.baidu.com";
    window.location.href=decodeURIComponent(URI);
    </script>
    </html>
    wwqgtxx
    wwqgtxx
    Apr 28, 2017
    3
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="shortcut icon" href="https://static.zhihu.com/static/favicon.ico" type="image/x-icon">
    <title>跳转中...</title>
    </head>
    <script>
    var URI = "https%3A%2F%2Fwww.baidu.com";
    window.location.href=decodeURIComponent(URI);
    </script>
    </html>
    huangtao728
    huangtao728
    Apr 28, 2017 via Android
    4
    可以跳转的原因见楼上
    我猜知乎用 200 来跳转而不是 302 是因为 302 不易缓存吧
    lmaq
    lmaq
    Apr 28, 2017
    5
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
    <link rel="shortcut icon" href="https://static.zhihu.com/static/favicon.ico" type="image/x-icon">
    <title>跳转中...</title>
    </head>
    <script>
    var URI = "https%3A%2F%2Fwww.baidu.com";
    window.location.href=decodeURIComponent(URI);
    </script>
    </html>
    eoo
    eoo
    Apr 28, 2017 via Android
    6
    少见多怪,难道跳转就一定要用 301 302 吗?
    Showfom
    Showfom
    PRO
    Apr 28, 2017 via iPhone
    7
    @huangtao728 302 为啥不容易缓存 所有状态都可以缓存啊 我猜测他们是为了检测流量走向吧
    Showfom
    Showfom
    PRO
    Apr 28, 2017 via iPhone
    8
    @huangtao728 而且头部都有 no-cache is 了 本身他们就没做缓存
    huangtao728
    huangtao728
    Apr 28, 2017 via Android
    9
    @Showfom

    嗯,仔细看了看 302 也可以

    不过我联想到知乎可以通过这种方式屏蔽某些链接(也确实这么干过),且避免目标网站从 Referer 获取源问题地址

    加上你说的检测流量导向,知乎真是心机 boy 啊
    ryd994
    ryd994
    Apr 28, 2017 via Android
    10
    @Showfom
    @huangtao728
    可是 302 也可以啊
    no cache 对 302 也是有效的
    而且 302 请求也是可以记录的啊
    我觉得是用户体验的问题,就是要提示以下内容不属于知乎
    torbrowserbridge
    torbrowserbridge
    Apr 28, 2017 via iPhone
    11
    我觉得原因就是可以显示 跳转中
    jininij
    jininij
    Apr 28, 2017 via Android❤️5
    12
    有一个中转页面,普通用户就能知道这里有一个跳转过程,302 则是对用户透明的。302 也可以检测流量啊。
    更关键的在 SEO 上,302 会把权重转移给 302 目标。哪怕使用了 rel="noreferrer" ,也会引导搜索引擎去爬取。知乎真是一点权重也不想外流啊。
    Dowding
    Dowding
    Apr 28, 2017
    13
    js 跳转的方式,普通的爬虫应该是获取不到跳转目标地址的。
    aksoft
    aksoft
    Apr 28, 2017
    14
    毛,就是为了 seo
    lslqtz
    lslqtz
    Apr 28, 2017
    15
    没搞懂知乎为什么是动态生成而不是根据参数跳转。。
    cwek
    cwek
    Apr 28, 2017
    17
    header 的话有 refresh
    js 的话 location.href
    cwek
    cwek
    Apr 28, 2017
    18
    @huangtao728 302 可以用 cache-control 处理吧
    flowfire
    flowfire
    Apr 28, 2017 via iPhone
    19
    一个是浏览器跳转的,w3c 规定的
    一个是 v8 跳转的,ECMAScript 规定的

    类似于一个在房门口看到路牌,XXX 地左转
    一个是进了房间,问了人,他说你走错了,出门左转
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   889 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 47ms · UTC 20:38 · PVG 04:38 · LAX 12:38 · JFK 15:38
    ♥ Do have faith in what you're doing.