Skip to main content

Создание настраиваемой страницы 404 для сайта GitHub Pages

Пользовательскую страницу с ошибкой 404 можно отображать, когда пользователи пытаются получить доступ к несуществующим страницам на сайте.

Кто эту функцию можно использовать?

GitHub Pages доступен в общедоступных репозиториях с GitHub Free и GitHub Free для организаций, а также в общедоступных и частных репозиториях с GitHub Pro, GitHub Team, GitHub Enterprise Cloudи GitHub Enterprise Server. Дополнительные сведения см. в разделе "Планы GitHub".

Все сборки GitHub Pages будут использовать GitHub Actions с 30 июня 2024 года. Другие изменения не требуются, но для продолжения сборки необходимо включить GitHub Actions в репозитории. Дополнительные сведения о включении GitHub Actionsсм. в разделе "Управление параметрами GitHub Actions для репозитория".

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

  2. Navigate to the publishing source for your site. For more information, see "Configuring a publishing source for your GitHub Pages site."

  3. Above the list of files, select the Add file dropdown menu, then click Create new file.

    Alternatively, you can click in the file tree view on the left.

    Screenshot of the main page of a repository. Above the list of files, a button, labeled "Add file," is outlined in dark orange. In the file tree view of the repository, a button with a plus sign icon is also outlined in dark orange.

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

  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. Click Commit changes...

  8. In the "Commit message" field, 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 authors."

  9. If you have more than one email address associated with your account on GitHub.com, click the email address drop-down menu and select the email address to use as the Git author email address. Only verified email addresses appear in this drop-down menu. If you enabled email address privacy, then a no-reply will be the default commit author email address. For more information about the exact form the no-reply email address can take, see "Setting your commit email address."

    Screenshot of a GitHub pull request showing a dropdown menu with options to choose the commit author email address. octocat@github.com is selected.

  10. Below the commit message fields, decide whether to add your commit to the current branch or to a new branch. If your current branch is the default branch, you should choose to create a new branch for your commit and then create a pull request. For more information, see "Creating a pull request."

    Screenshot of a GitHub pull request showing a radio button to commit directly to the main branch or to create a new branch. New branch is selected.

  11. Click Commit changes or Propose changes.

Further reading