301/302 with document body showing 'click here if your browser doesn't redirect you' anchor

為{幸葍}努か 提交于 2019-12-25 03:49:15

问题


We will be implementing a tiny document body with all our 301 and 302 responses.

They will contain a small bit of html with an anchor pointing towards the URL where the user should be redirected.

Are there any pitfalls or things we should know about when doing this or is it as simple as including the html in the document body when sending out a 'location' header?


回答1:


If browser will see 301/302 HTTP result code it will IGNORE document/response body and will do instant redirect to the URL specified in Location: response header.


But yes -- you can display such page and do redirect to a new URL .. but this will be the same as normal click on a link (and not 301/302 redirect in any means) and therefore is not good for SEO purposes. If interested -- this is how it can be done:

When user hits such page, show him/her your redirect message/page. In that page such redirect can be achieved in 2 ways:

  1. Using JavaScript -- window.location = "http://www.example.com/new-url". All what you need to do is to execute this code 10 seconds after page is loaded -- for that use setTimeout() functionality.

  2. Without JavaScript (preferred method as it will work even if JavaScript is disabled or not available) using <meta http-equiv="refresh" header line:

    <meta http-equiv="refresh" content="10; url=http://www.example.com/new-url">



来源:https://stackoverflow.com/questions/7060451/301-302-with-document-body-showing-click-here-if-your-browser-doesnt-redirect

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