> 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 の組織で、サイドバーにあるドキュメントサイト名をクリックし、次に **サイトを管理** をクリックするか、 **設定** タブを開きます。 **ドメインとリダイレクト** セクションを開き、「サブディレクトリ」の下にある **サブディレクトリを設定**.

ドキュメントをホストする URL を入力します。次に、ドキュメントへのアクセスに使用するサブディレクトリを指定します。例: `tomatopy.pizza/docs`を入力して、 **設定**.

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

{% step %}

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

Cloudflareアカウントにサインインし、次のページに移動します **Workers & Pages**.

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

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

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

{% step %}

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

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

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

{% step %}

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

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.
