Search code examples
google-chromehttpgoogle-searchhttp-status-code-302

How does Google redirect its search results?


I input the query java into the search text box on https://www.google.com. One result is https://en.wikipedia.org/wiki/Java_(programming_language). I get the following text by right clicking the link and selecting Copy Link Address.

https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=10&cad=rja&uact=8&ved=0ahUKEwiijvLpqvnSAhVFqY8KHU5UDyYQFghDMAk&url=%68%74%74%70%73%3a%2f%2f%65%6e%2e%77%69%6b%69%70%65%64%69%61%2e%6f%72%67%2f%77%69%6b%69%2f%4a%61%76%61%5f%28%70%72%6f%67%72%61%6d%6d%69%6e%67%5f%6c%61%6e%67%75%61%67%65%29&usg=AFQjCNEaMDPWkK-lszS-jjSYrWuKEdrmKA&bvm=bv.150729734,d.dGc

And I paste the above link to Chrome address bar. And I use Developer Tools to monitor the HTTP network traffic.

enter image description here

The first HTTP request is for the original link. And its status code is 200. How does Chrome make the following request for https://en.wikipedia.org/wiki/Java_(programming_language)?I know that a HTTP response with status code 302 can make brsowers following the link in Location header. But how is the redirect done in this case with status code 200?


Solution

  • The redirect is done because in the response of the first HTTP request (https://www.google.com/url?sa=t&rct=j...):

    • If javascript is enabled, then the window location is navigated to https://en.wikipedia.org/... using script.
    • If javascript is disabled, or client does not support javascript, then <meta http-equiv="refresh"> is used to redirect to https://en.wikipedia.org/...

    Here is the response body of the first HTTP request:

    <script>window.googleJavaScriptRedirect=1</script>
    <META name="referrer" content="origin">
    <script>var n={navigateTo:function(b,a,d){if(b!=a&&b.google){if(b.google.r){b.google.r=0;b.location.href=d;a.location.replace("about:blank");}}else{a.location.replace(d);}}};n.navigateTo(window.parent,window,"https://en.wikipedia.org/wiki/Java_(programming_language)");
    </script>
    <noscript>
    <META http-equiv="refresh" content="0;URL='https://en.wikipedia.org/wiki/Java_(programming_language)'">
    </noscript>