404页面是网站必须设置
404页面是指用户在访问网站时,服务器无法找到请求的页面,返回的页面。404页面是网站必须设置的,因为它是用户在访问网站时遇到错误时看到的页面。告知用户该网页不存在或已被删除。
404页面设置方法
在网站根目录下创建一个名为404.html的文件。
在404.html文件中添加符合标准的404代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>404 Not Found</title>
</head>
<body>
<h1>404 Not Found</h1>
<p>Sorry, the page you are looking for could not be found.</p>
</body>
</html>
- 在服务器配置文件中添加404页面重定向规则
server {
listen 80;
server_name example.com;
root /var/www/html;
error_page 404 /404.html;
location = /404.html {
internal;
}
}
4 . 在Apache服务器配置文件中添加404页面重定向规则
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html
ErrorDocument 404 /404.html
</VirtualHost>
- 在IIS服务器配置文件中添加404页面重定向规则
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="404" subStatusCode="-1" />
<error statusCode="404" path="/404.html" responseMode="ExecuteURL" />
</httpErrors>
</system.webServer>
- 或是使用宝塔的朋友添加404页面重定向规则
使用宝塔网站设置的重定向功能,有个404跳转,按上图设置好即可。
#SSL-START SSL相关配置,请勿删除或修改下一行带注释的404规则
#error_page 404/404.html;
#HTTP_TO_HTTPS_START
404页面设置注意事项
404页面不要直接跳转到网站首页,这将导致首页不被收录。
404页面前边不要到主域名,否则返回的状态码是302,而不是404。
404页面要简洁明了,不要有太多的广告和链接。
404页面要设置好SEO,方便搜索引擎收录。最好底部加入导航尤其是网站地图。
404页面要设置好缓存,避免每次访问都重新生成页面。
404页面要设置好访问权限,防止恶意访问。
总结:404页面是网站必须设置的,因为它是用户在访问网站时遇到错误时看到的页面。设置404页面时要注意不要直接跳转到网站首页,要简洁明了,设置好SEO,设置好缓存,设置好访问权限。