问题
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:
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 usesetTimeout()
functionality.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