当用户访问一个不存在的网页时,可以使用以下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 - 页面无法找到</title>
  <style>
    body {
      font-family: Arial, sans-serif;
      background-color: #f1f1f1;
      text-align: center;
      padding: 50px;
    }
    
    h1 {
      font-size: 36px;
    }
    
    p {
      font-size: 18px;
    }
    
    a {
      color: #0060ac;
      text-decoration: none;
    }
    
    a:hover {
      text-decoration: underline;
    }
  </style>
</head>
<body>
  <h1>404 - 页面无法找到</h1>
  <p>很抱歉,您访问的页面不存在。</p>
  <p>请检查您输入的网址是否正确,或点击<a href='https://www.google.com'>这里</a>返回谷歌首页。</p>
</body>
</html>

将上述代码保存为一个HTML文件(例如404.html),然后在服务器上将该文件命名为404.html,并确保在服务器配置中将错误页面指向该文件。这样,当用户访问一个不存在的网页时,就会显示自定义的 404 页面。

自定义404页面 - 谷歌浏览器错误页面HTML代码

原文地址: https://www.cveoy.top/t/topic/qiLG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录