Client Web Browser Behavior When Handling 301 Redirect

偶尔善良 提交于 2019-12-03 10:05:27
Bavi_H

I preformed some tests and found some browsers do cache the 301 result:

Caches 301 result and skips contacting old address in future?

  Internet Explorer 7   no
  Firefox 3.0           no
  Chrome 4.0            yes
  Opera 10.01           yes for google.com, no for www.rnhart.net

How I tested

I used the following two 301 results to test with:

  • google.com returns a 301 to www.google.com
  • www.rnhart.net returns a 301 to rnhart.net

I started a proxy server on my own computer (Proxomitron Naoko 4.2 with all filters turned off). In each browser, I set the proxy settings to point to my own computer. I cleared the browser's cache, then I visited the old address multiple times and looked in the proxy server's log window to see what requests the browser made.

The first time the old address is visited, the proxy log shows the old address request, the 301 response, and the new address request. If the old address is visited again, the log either showed the same set of requests (the 301 wasn't cached), or it showed only the new address request (the 301 was cached).

I tested entering the old address in the address box, accessing the old address from a bookmark, and accessing the old address from a link on a page. Each browser worked the same way no matter how the address was accessed.


[I found this question while investigating a similar Super User question: Do browsers change URLs of saved bookmarks in response to 301 redirection?]

Andre

You may use this workaround:
Make 302 redirect for users and 301 only for search engines. On the server side, just check for the user agent. If it is a bot, do a 301 redirect. Otherwise, do 302.

It is not the "golden way", but it works great

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!