更改apache站点默认
The apache’s default “404 Error not found” page seems ugly. And may some hosting service put theire ads in it. We can add some entry in .htaccess to change the defualt 404 error page. This method can also be used for some other error codes. A list of the server returned codes can be found in Table 1.
apache的默认“ 404 Error not found”页面看起来很丑。 也许某些托管服务会将其广告投放其中。 我们可以在.htaccess中添加一些条目以更改默认404错误页面。 此方法也可以用于其他一些错误代码。 表1中列出了服务器返回的代码。
It simply need to add the “ErrorDocument” command to the .htaccess file. The format is:
只需要将“ ErrorDocument”命令添加到.htaccess文件中。 格式为:
ErrorDocument code /dir/file.ext
or
要么
ErrorDocument code http://mydomain.name/dir/file.ext
For example:
例如:
ErrorDocument 404 /404.html
would cause any error code resulting in 404 to be forwarded to mydomain.name/404.html
会导致导致404的任何错误代码转发到mydomain.name/404.html
ErrorDocument 404 https://www.systutorials.com/p/404.html
would cause any error code resulting in 404 to be forwarded to https://www.systutorials.com/p/404.html
会导致导致404的任何错误代码转发到https://www.systutorials.com/p/404.html
For other error code such as 401 the method is the same. But not all the returned code should be forwarded. Most of the time, forwarding the error codes is enough.
对于其他错误代码(例如401),方法相同。 但并非所有返回的代码都应转发。 在大多数情况下,转发错误代码就足够了。
Table1: Server returned codes
表1:服务器返回的代码
Successful Client Requests | |
200 | OK |
201 | Created |
202 | Accepted |
203 | Non-Authorative Information |
204 | No Content |
205 | Reset Content |
206 | Partial Content |
Client Request Redirected | |
300 | Multiple Choices |
301 | Moved Permanently |
302 | Moved Temporarily |
303 | See Other |
304 | Not Modified |
305 | Use Proxy |
Client Request Errors | |
400 | Bad Request |
401 | Authorization Required |
402 | Payment Required (not used yet) |
403 | Forbidden |
404 | Not Found |
405 | Method Not Allowed |
406 | Not Acceptable (encoding) |
407 | Proxy Authentication Required |
408 | Request Timed Out |
409 | Conflicting Request |
410 | Gone |
411 | Content Length Required |
412 | Precondition Failed |
413 | Request Entity Too Long |
414 | Request URI Too Long |
415 | Unsupported Media Type |
Server Errors | |
500 | Internal Server Error |
501 | Not Implemented |
502 | Bad Gateway |
503 | Service Unavailable |
504 | Gateway Timeout |
505 | HTTP Version Not Supported |
成功的客户要求 | |
200 | 好 |
201 | 已建立 |
202 | 公认 |
203 | 非权威信息 |
204 | 无内容 |
205 | 重设内容 |
206 | 部分内容 |
客户请求已重定向 | |
300 | 多项选择 |
301 | 永久移动 |
302 | 暂时移动 |
303 | 查看其他 |
304 | 未修改 |
305 | 使用代理 |
客户请求错误 | |
400 | 错误的请求 |
401 | 需要授权 |
402 | 需要付款(尚未使用) |
403 | 禁止的 |
404 | 未找到 |
405 | 不允许的方法 |
406 | 不可接受(编码) |
407 | 需要代理身份验证 |
408 | 请求超时 |
409 | 要求冲突 |
410 | 走了 |
411 | 内容长度要求 |
412 | 前提条件失败 |
413 | 请求实体太长 |
414 | 请求URI太长 |
415 | 不支持的媒体类型 |
服务器错误 | |
500 | 内部服务器错误 |
501 | 未实现 |
502 | 错误的网关 |
503 | 暂停服务 |
504 | 网关超时 |
505 | 不支持HTTP版本 |
翻译自: https://www.systutorials.com/how-to-change-the-sites-default-404-error-not-found-page/
更改apache站点默认