What HTTP status code use when displaying alternat

2019-07-07 14:58发布

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.

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.

Thanks for your time and effort.

1条回答
Root(大扎)
2楼-- · 2019-07-07 15:08

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

  • 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).

  • 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 :

  • 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.

  • 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 response codes source : http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

查看更多
登录 后发表回答