Custom Error 404 interface

Under IE solve custom HTTP error page is too small and does not display a friendly error page displays the default lead to problems

I have seen such a sentence Ticket # 11289, IE bug fix: always pad the error page with enough characters such that it is greater than 512 bytes, even after gzip compression, and looks like IE Bug matter what, Google Instant, found WordPress original Bug handling page "Internet Explorer, 512-byte error page FIX does not Work. neglects to gzip compression." .

By the above description that when a custom HTTP error page (Custom HTTP Error Page) size is too small, is less than a critical threshold (thresholds), IE browser will automatically internal error page (Microsoft-stylin 'error page) to replace you custom error page.

What does that mean? First we have to understand what is the custom HTTP error page. Of course, to be understood that HTTP status code (HTTP Status Code), for example, we can not find the page server 404 returns a status code indicating that the page can not be found, when we redirect 301 or 302 is performed by the status code , of course, there is some additional information, such as status, information is written to the corresponding HTTP header (HTTP Response header) in the only browser and other clients can "see" and understand the information, and then translated to convey to us, here to send a page is not found status header:

HTTP/1.1 404 Not Found
Server: nginx
Date: Mon, 05 Mar 2012 08:20:41 GMT
Content-Type: text/html
Content-Length: 564
Connection: keep-alive
Keep-Alive: timeout=5

Which HTTP / 1.1 404 Not Found This is our concern, HTTP protocol representation, express version 1.1, the status code 404, Not Found indicates the state, then the Header tells the browser can not find the page, I just said this is sent by the server, of course, I purposely visited a page that does not exist, the server sends only 404 messages learned any Web programming language the students know that this also may be customized, such as PHP, we write can achieve the same function, even if the page is there:

<?php header("HTTP/1.1 404 Not Found"); ?>

Well, I'm here for demonstration purposes, for a status code of 500, indicating that the server error:

<?php header('HTTP/1.1 500 Internal Server Error'); ?>

This page indicates that we now have access to customized a 500 Internal Server Error HTTP error page, and the browser and other clients may also understand this error page, of course, we need to provide some additional information to inform our visitors, current error page a:

<?php header('HTTP/1.1 500 Internal Server Error'); ?>
<html>
<head>
  <title>Error</title>
</head>
<body bgcolor="white">
  <center><h1>当前页面出错咯</h1></center>
</body>
</html>

Tip: header must be sent before any HTML or text output, otherwise invalid.

Well, the above code is written to the file and upload 500.php server, and then browse through the browser, Chrome under normal display as "current page fault slightly" text that we have set, in IE but displays its internal built the "HTTP 500 internal server error, can not be displayed.

Let us return to the beginning of this article that IE Bug, Bug reflects the fact that this issue, when the server response content length less than a certain critical threshold (thresholds), IE browser will automatically ignore server after sending the response header custom text, that is, we set the text ignored by IE, and IE is replaced by its own internal error page (Microsoft-stylin 'error page). We just look at the size of the page:

For the 500 error threshold IE default setting is 512 bytes (additional threshold described later), it is clear that we have just constructed page is less than 512 bytes, so IE does not show our page, well, we certainly think, if more than this threshold (thresholds), then our page will not display normally? Congratulations, you answered correctly! For example, we will artificially filled trash page value to be larger than 512 bytes, of course, in order not to affect the overall page, we put it into HTML comments:

<?php header('HTTP/1.1 500 Internal Server Error'); ?>
<html>
<head>
  <title>Error</title>
</head>
<body bgcolor="white">
  <center><h1>当前页面出错咯</h1></center>
<!-- <?php echo str_repeat('*', 256); ?> -->
</body>
</html>

It is clear now that the page size is greater than the threshold value of 512, if we now have access to the page with IE, if not turn off the display friendly HTTP error messages, will display the text of the message of our own.

500 Internal Server Error

Of course, to note here there Gzip, if the page already here greater than 512 bytes, but after gzip compression output page but less than 512 bytes, then IE will still use their own error pages to replace our mistakes too, so here filled with garbage values ​​to take this into consideration, due to the compression characteristics, high compression efficiency repeated characters, we have to expand the volume does not want to see this effect, it is necessary to use non-repeating random character filled, which is why I am afraid the beginning WP filling reason it's messy characters.

This threshold actually have such a magical effect, then how do we get a different error page IE default critical threshold it? Here are a list for your reference:

Code description File size (threshold)
400 Bad Request > 512 bytes
403 Forbidden > 256 bytes
404 Not Found > 512 bytes
405 Method Not Allowed > 256 bytes
406 Not Acceptable > 512 bytes
408 Request Time-out > 512 bytes
409 Conflict > 512 bytes
410 Gone > 256 bytes
500 Internal Server Error > 512 bytes
501 Not Implemented > 512 bytes
505 HTTP Version Not Supported > 512 bytes

Of course, on top of that table is not groundless, according to the IE configuration, this configuration is saved in the registry HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Internet Explorer \ Main \ ErrorThresholds, you can change this value Edit:

Registry modifications display threshold (thresholds) IE error page

Just see the default error page Nginx, such as 404 error, but also the application of appropriate techniques to avoid this problem:

Nginx 404 error page source file

<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->
<!-- a padding to disable MSIE and Chrome friendly error page -->

But look at the literal meaning, looks like Chrome also have this characteristic? And tried it, looks like IE or Chrome only access we have so few lines of HTML comments Padding.

Also some browsers housing, may capture the HTTP error head, in order to show its built-in page, if so, the trick here will not work, it is recommended that you use the major browsers.

Original link: https://wangye.org/blog/archives/559/

 

Guess you like

Origin www.cnblogs.com/Gouwa/p/12453304.html