# リダイレクトを構成する

記事のタイトル、バージョン、または場所が変更された場合は、現在のコンテンツへのリダイレクトを作成できます。

## リダイレクトについて

ユーザーの検索機能に影響する記事に変更が加えられた場合、古いバージョンから現在のコンテンツへのリダイレクトが作成されます。 記事のタイトルが変更された場合、新しいバージョンが追加された場合、またはファイルの場所が変更された場合に、これを行う必要があります。

リダイレクトは、ローカルまたは外部で構成できます。

## ローカル リダイレクトの構成

GitHub Docs 内では、あるファイルから別のファイルに、またはあるバージョンから別のバージョンにリダイレクトできます。

### ファイル間でのリダイレクト

記事の名前を変更し、そのすべてのバージョンの古い URL を新しい URL にリダイレクトする場合は、記事の古い名前へのパスを含む `redirect_from` frontmatter を使用します。 記事の名前を変更し、異なるバージョンを異なる URL にリダイレクトしたい場合は、「[バージョン間でのリダイレクト](#redirects-across-versions)」セクションの手順に従って行います。

次の例では、「All about commits」という記事の名前が「Creating your first commit」に変更されました。
`redirect_from` frontmatter は、古い記事の URL にアクセスするすべてのユーザーを新しい記事の URL にリダイレクトします。

```yaml
title: Creating your first commit
redirect_from:
  - /content/get-started/all-about-commits
```

詳細については、GitHub Docs README ファイル内の [`redirect_from`](https://github.com/github/docs/blob/main/content/README.md#redirect_from) を参照してください。

### バージョンが含まれていない URL の自動リダイレクト

ページの URL がバージョンなしで入力された場合 (`https://docs.github.com/ARTICLE` ではなく `https://docs.github.com/VERSION/ARTICLE`)、サイトはページの最初の使用可能なバージョンに自動的にリダイレクトします。<!-- markdownlint-disable-line search-replace -->

優先順位は [`lib/all-versions.ts`](https://github.com/github/docs/blob/main/src/versions/lib/all-versions.ts) で指定します。 現在の優先順位は次のとおりです。

1. GitHub Free、GitHub Pro、または GitHub Team (`fpt`)
2. GitHub Enterprise Cloud(`ghec`)
3. GitHub Enterprise Server (`ghes`)

`ARTICLE` というタイトルのページが GitHub Enterprise Cloud と GitHub Enterprise Server でのみ使用可能な場合、GitHub Enterprise Cloud は GitHub Enterprise Server よりも優先されるため、リンク `https://docs.github.com/ARTICLE` は自動的に `https://docs.github.com/enterprise-cloud@latest/ARTICLE` にリダイレクトします。<!-- markdownlint-disable-line search-replace -->

Free、Pro、Team のいずれかで `ARTICLE` が使用可能な場合、`fpt` ページにバージョン セグメントがないため、リダイレクトは発生しません。`fpt` の `https://docs.github.com/ARTICLE` コンテンツがレンダリングされます。<!-- markdownlint-disable-line search-replace -->

### バージョン間でのリダイレクト

あるバージョンの記事の URL を別のバージョンの URL にリダイレクトするか、完全に別の URL にリダイレクトする場合は、[](https://github.com/github/docs/blob/main/src/redirects/lib/static/redirect-exceptions.txt) ディレクトリ内の `src/redirects` ファイルを更新する必要があります。

たとえば、記事の Free、Pro、または Team (`fpt`) バージョンを削除すると、URL は次に使用可能なバージョンのページに自動的にリダイレクトされます。 優先順位の低いバージョンにリダイレクトする場合、または別のページに完全にリダイレクトする場合は、例外を指定する必要があります。

`redirect-exceptions` ファイル内の各エントリは、バージョンを含むリダイレクト\_先\_のパスで始まり、その次にリダイレクト\_元\_パスの順序なしリストが続いたものでなければなりません。 次の例では、順序が指定されていないリスト内のパスは、GitHub Enterprise Cloud バージョンの「[組織のメンバー情報をエクスポートする](/ja/enterprise-cloud@latest/organizations/managing-membership-in-your-organization/exporting-member-information-for-your-organization)」にリダイレクトされます。

```text
/enterprise-cloud@latest/organizations/managing-membership-in-your-organization/exporting-member-information-for-your-organization
  - /enterprise-server@3.3/organizations/managing-membership-in-your-organization/exporting-member-information-for-your-organization
  - /enterprise-server@3.4/organizations/managing-membership-in-your-organization/exporting-member-information-for-your-organization
  - /enterprise-server@3.5/organizations/managing-membership-in-your-organization/exporting-member-information-for-your-organization
```

## 外部リダイレクトを構成する

コンテンツが GitHub Docs サイトの外部に移動されることはほとんどありません。 このような種類のリダイレクトの場合は、`external-sites.json` ディレクトリ内の [](https://github.com/github/docs/blob/main/src/redirects/lib/external-sites.json) ファイルを更新します。

`external-sites.json` ファイル内の各エントリはキーと値のペアで、キーはコンテンツが置かれた場所へのパスであり、値はリダイレクト先のパスです。

```json
  "/github-status": "https://www.githubstatus.com/",
  "/articles/github-security": "https://github.com/security",
```