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

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

  •  
  •   TypeErrorNone · Apr 28, 2017 · 8059 views
    This topic created in 3326 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
        1
    TypeErrorNone  
    OP
       Apr 28, 2017
    gracece
        2
    gracece  
       Apr 28, 2017
    ~ 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
        3
    wwqgtxx  
       Apr 28, 2017
    <!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
        4
    huangtao728  
       Apr 28, 2017 via Android
    可以跳转的原因见楼上
    我猜知乎用 200 来跳转而不是 302 是因为 302 不易缓存吧
    lmaq
        5
    lmaq  
       Apr 28, 2017
    <!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
        6
    eoo  
       Apr 28, 2017 via Android
    少见多怪,难道跳转就一定要用 301 302 吗?
    Showfom
        7
    Showfom  
    PRO
       Apr 28, 2017 via iPhone
    @huangtao728 302 为啥不容易缓存 所有状态都可以缓存啊 我猜测他们是为了检测流量走向吧
    Showfom
        8
    Showfom  
    PRO
       Apr 28, 2017 via iPhone
    @huangtao728 而且头部都有 no-cache is 了 本身他们就没做缓存
    huangtao728
        9
    huangtao728  
       Apr 28, 2017 via Android
    @Showfom

    嗯,仔细看了看 302 也可以

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

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

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