浏览器如何请求404自定义错误页面?

浏览器如何请求404自定义错误页面?

我试图了解在出现自定义错误消息的情况下浏览器和服务器之间的通信如何进行。

我理解 301/302 标头包含相关页面的 URL,

HTTP/1.1 30x ....
Location: http://www.example.org/

但 404 标头没有(据我所知)。

是什么告诉浏览器获取错误页面?我没有网络嗅探器,这个问题本身在谷歌上产生了大量的噪音

这是我跟踪 http 时看到的内容:

GET http: //myserver.com/unknownpage HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: en-gb
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Proxy-Connection: Keep-Alive
Host: myserver.com
Cookie: ...

HTTP/1.1 404 Not Found
Date: Wed, 30 Jan 2013 08:54:52 GMT
Server: Apache
Content-Type: text/html;charset=ISO-8859-1
Transfer-Encoding: chunked
Proxy-Connection: Keep-Alive
Connection: Keep-Alive


GET http: //myserver.com/errorpages/error404.htm HTTP/1.1
Accept: image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
Accept-Language: en-gb
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.0.3705; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.1; .NET4.0C; .NET4.0E)
Accept-Encoding: gzip, deflate
Proxy-Connection: Keep-Alive
Host: myserver.com
Pragma: no-cache
Cookie: ...

HTTP/1.1 200 OK
Date: Wed, 30 Jan 2013 08:54:52 GMT
Server: Apache
Last-Modified: Tue, 22 Jan 2013 16:14:07 GMT
Accept-Ranges: bytes
Content-Type: text/html
Content-Length: 5958
Proxy-Connection: Keep-Alive
Connection: Keep-Alive
Age: 0

所以我的问题是究竟是什么告诉浏览器去获取自定义页面?我知道如何在 Apache 上进行设置,我的问题是关于通信的

答案1

当针对每个特定的 HTTP 错误代码进行配置时,Web 服务器只会将配置的页面返回给浏览器。

实际上,您正在用自定义页面替换出现特定错误时提供的默认页面。

相关内容