> 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/publish/custom-domain/setting-a-custom-subdirectory/configuring-a-subdirectory-with-cloudflare.md).

# Cloudflare でサブディレクトリを設定する

Cloudflare を使って /docs サブディレクトリでドキュメントをホストします

{% stepper %}
{% step %}

#### GitBookサイトの設定

GitBook の組織で、サイドバーのドキュメントサイト名をクリックし、次に **サイトを管理** または **設定** タブを開いて **ドメインとリダイレクト** セクションを開き、「Subdirectory」の下で、クリック **サブディレクトリを設定**.

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

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

{% step %}

#### Cloudflare Worker を作成する

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

をクリックするか、 **作成** ボタン。

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

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

{% step %}

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

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

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

{% step %}

#### Worker コードを更新する

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

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

{% code lineNumbers="true" %}

```javascript
export default {
  fetch(request) { 
    const SUBDIRECTORY = '/docs';
    const url = new URL(request.url);
    const target = "<INSERT YOUR PROXY URL FROM GITBOOK>" + 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" %}
最初の手順で GitBook から取得したプロキシ URL を使って、5 行目の 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

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

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
