301/302,文档主体显示“如果浏览器不重定向您,请单击此处" [英] 301/302 with document body showing 'click here if your browser doesn't redirect you' anchor

查看:158
本文介绍了301/302,文档主体显示“如果浏览器不重定向您,请单击此处"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将使用所有301和302响应来实现一个小的文档正文.

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

它们将包含一小段html和锚点,该锚点指向应将用户重定向到的URL.

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

执行此操作时是否有任何陷阱或我们应该知道的事情,还是像发送位置"标头时在文档正文中包含html一样简单?

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?

推荐答案

如果浏览器将看到301/302 HTTP结果代码,它将 IGNORE 文档/响应正文,并将立即重定向到指定的URL在Location:响应标头中.

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.

但是,是的-您可以显示该页面并重定向到新的URL ..但这将与常规点击链接相同(并且无论如何都不会以301/302重定向) ),因此不适用于SEO.如果有兴趣-这是可以完成的方法:

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. 使用JavaScript-window.location = "http://www.example.com/new-url".您需要做的就是在页面加载后10秒钟执行此代码-为此使用setTimeout()功能.

  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.

使用<meta http-equiv="refresh"标题行不使用JavaScript(首选方法,即使禁用了JavaScript也不可用,它仍然可以使用):

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">

这篇关于301/302,文档主体显示“如果浏览器不重定向您,请单击此处"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆