显示旧浏览器的备用错误页面时,HTTP状态代码使用了什么? [英] What HTTP status code use when displaying alternative error page for old browsers?

查看:109
本文介绍了显示旧浏览器的备用错误页面时,HTTP状态代码使用了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站大量使用CSS3和一些HTML5现代功能。所以它在IE7或更低版​​本中不起作用,看起来非常糟糕。我们的决定是我们不会支持这些旧浏览器,因为它对很少用户来说太过分了。他们没有显示常规页面,而是看到特殊的错误/警告页面,他们告诉他们为什么会看到它以及他们应该安装更新的浏览器。

I have a website that heavily uses CSS3 and some HTML5 modern features. So it doesn't work in IE7 or lower and looks very bad. The decision was that we will not support these old browsers as it is too much work for very few users. Instead of displaying regular page, they see special error/warning page, where they informed about why they see it and that they should install newer browser.

这样可以正常工作。但我的问题是 - 我应该使用此页面发送什么HTTP状态代码?有关系吗 ?现在,它是正常的200 OK。

This works fine. But my question is - what HTTP status code should I send with this page ? Does it matter ? Right now, it's regular 200 OK.

感谢你的时间和精力。

推荐答案

你有几个选择,它们主要取决于两个参数:

You have several choices here, and they would mainly depend on two parameters :


  • 状态代码是否合适对于这样的问题,是否允许在不涉及 HTTP事务但发送到浏览器的内容的条件下使用它? (浏览器显然不通过HTTP告诉它是否支持给定的HTML / CSS标准。)

  • Is the status code appropriate to such an issue, is it even allowed to use it in a condition that does not involve an HTTP transaction but the content that is sent to the browser ? (the browser obviously does not tell via HTTP whether it supports a given HTML/CSS standard).

浏览器将如何解释它。某些浏览器在收到特定状态代码时甚至无法渲染已发送的HTML,而是显示默认的内置页面。

How it is going to be interpreted by the browser. Some browser, when they receive a specific status code doesn't even bother to render the sent HTML and displays instead a default built-in page.

我要做的是选择一个正确记录的错误代码并将其用作语义响应,并确保浏览器不忽略正文。我建议两种不同的解决方案:

What I would do is choose a properly documented error code and use it as a semantic response, and make sure the browser isn't ignoring the body. I would suggest two different solutions :


  • 回复 302找到最初请求的资源,并在发送 200 OK 时将浏览器重定向到您的错误页面。这就是大多数网站管理员在出现这样的问题时所做的事情,主要是因为 HTTP事务本身没有任何失败,只是我们正在重定向用户,因此可以根据额外的HTTP生成正确的视图参数。

  • Responding a 302 Found on the initially requested resource, and redirecting the browser to your error page while sending a 200 OK. This is what most webmasters do when such a problem arises, mainly because nothing failed in the HTTP transaction itself, it is just that we are redirecting the user so a proper view can be generated according to extra-HTTP parameters.

通过告诉浏览器发生的事情,为您的回复提供语义错误代码。同样,浏览器如何对此错误代码做出反应是依赖于实现的,并且可能会发生很大变化。显然,应该返回 4xx状态代码,因为它旨在向客户端发出信号错误。我很想使用 415 Unsupported Media Type 417期望失败

Giving a semantical error code to your response by telling the browser what happened. Again, how the browser can react to this error code is implementation-dependant and can strongly vary. Obviously, a 4xx status code should be returned as it is intended to signal a client-side error. I will be tempted to use a 415 Unsupported Media Type or a 417 Expectation Failed.

HTTP响应代码来源: http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

HTTP response codes source : http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

这篇关于显示旧浏览器的备用错误页面时,HTTP状态代码使用了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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