> For the complete documentation index, see [llms.txt](https://gitbook.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gitbook.com/docs/documentation/ja-gitbook-documentation/gong-kai/custom-domain/setting-a-custom-subdirectory/configuring-a-subdirectory-with-cloudflare.md).

# Cloudflare を使ったサブディレクトリの設定

{% stepper %}
{% step %}

#### GitBookサイトの設定

GitBook 組織で、サイドバーの docs サイト名をクリックし、次に **サイトを管理** をクリックするか、 **設定** タブを開きます。 **ドメインとリダイレクト** セクションを開き、『Subdirectory』の下で、 **サブディレクトリを設定**.

ドキュメントをホストしたいURLを入力してください。次に、ドキュメントにアクセスするためのサブディレクトリを指定します。例: `tomatopy.pizza/docs`、そしてクリック **設定**.

の下で **追加設定**、プロキシ URL が表示されます。次の手順で Cloudflare ワーカーを設定する際にこれを使用します。クリップボードにコピーしてください。
{% endstep %}

{% step %}

#### Cloudflare ワーカーを作成

Cloudflare アカウントにサインインし、次へ移動します **Workers & Pages**

をクリックします **作成** ボタン。

「アプリケーションを作成」画面で、次をクリックします **Hello world** 「テンプレートから開始」カード内のボタン。

ワーカーに、たとえば次のような、よりわかりやすい名前を付けます `mydocs-subpath-proxy`。ワーカーの名前変更が完了したら、次をクリックします **デプロイ**.
{% endstep %}

{% step %}

### カスタムドメインを設定

ワーカーには、使用できるデフォルト URL が割り当てられます。代わりにカスタムドメインを設定するには（たとえば `tomatopy.pizza`）、次をクリックします **設定。** 次に、「Domains & Routes」セクションで、次をクリックします **+ 追加**.

開いた「Domains & Routes」トレイで、次をクリックします **カスタムドメイン**、その後、続くテキストボックスにカスタムドメインを入力します。カスタムドメインを指定する際は、 *含めないでください* サブディレクトリを含めません。たとえば、 `tomatopy.pizza` は正しく、 `tomatopy.pizza/docs` は正しくありません。
{% endstep %}

{% step %}

#### ワーカーのコードを更新

ワーカーのデプロイが完了したら、次をクリックします **コードを編集**、または次をクリックします **プロジェクトに進む**、その後、 **コードを編集** 右上のボタン。

開いたコードエディタで、サンプルコードを次のスニペットに置き換えます：

{% code lineNumbers="true" %}

```javascript
export default {
  fetch(request) { 
    const SUBDIRECTORY = '/docs';
    const url = new URL(request.url);
    const target = "<GITBOOK から取得したプロキシ URL を入力>" + url.pathname.slice(SUBDIRECTORY.length);
    const proxy = new URL(
      target.endsWith('/') ? target.slice(0, -1) : target 
    )
    proxy.search = url.search;
    return fetch(new Request(proxy, request));
  }
};
```

{% endcode %}

{% hint style="info" %}
必ず 5 行目の URL を、最初の手順で GitBook から取得したプロキシ URL に更新してください。
{% endhint %}

完了したら、次をクリックします **デプロイ**。この प्रक्रियाには数分かかる場合があります。完了したら、その URL にアクセスすると、ドキュメントサイトが表示されるはずです！
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gitbook.com/docs/documentation/ja-gitbook-documentation/gong-kai/custom-domain/setting-a-custom-subdirectory/configuring-a-subdirectory-with-cloudflare.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
