我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

为 GitHub Pages 站点创建自定义 404 页面

您可以自定义在人们尝试访问您站点上不存在的页面时显示的 404 错误页面。

GitHub Pages is available in public repositories with GitHub Free, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise Server. For more information, see "GitHub's products."

  1. On GitHub, navigate to your site's repository.

  2. Navigate to the publishing source for your site. 有关发布源的更多信息,请参阅“关于 GitHub Pages”。

  3. Above the file list, click Create new file.

    The New file button

  4. In the file name field, type 404.html or 404.md.

    File name field

  5. If you named your file 404.md, add the following YAML front matter to the beginning of the file:

    ---
    permalink: /404.html
    ---
    
  6. Below the YAML front matter, if present, add the content you want to display on your 404 page.

  7. At the bottom of the page, type a short, meaningful commit message that describes the change you made to the file. You can attribute the commit to more than one author in the commit message. For more information, see "Creating a commit with multiple co-authors."

    有关更改的提交消息

  8. 以下是提交消息字段,请单击电子邮件地址下拉菜单并选择 Git 作者电子邮件地址。 只有经过验证的电子邮件地址才会出现在此下拉菜单中。 如果您启用了电子邮件地址隐私保护,则 <username>@users.noreply.github.com 为默认的提交作者电子邮件地址。 更多信息请参阅“设置提交电子邮件地址”。

    Choose commit email addresses

  9. 在提交消息字段下面,确定是要将提交添加到当前分支还是新分支。 If your current branch is master, you should choose to create a new branch for your commit and then create a pull request. For more information, see "Creating a new pull request."

    提交分支选项

  10. Click Propose new file.

    Propose new file button

延伸阅读

问问别人

找不到要找的内容?

联系我们