Skip to content

非公式本サイトは非公式の日本語ドキュメントであり、Cloudflare 公式サイトではありません。最新情報はdevelopers.cloudflare.comをご確認ください。

HTML の扱い

最終更新 Markdown で表示Agent セットアップ

リクエストパスの末尾スラッシュを強制するか落とすか(例: example.com/page/example.com/page)は、見た目のために制御したいことがよくあります。SEO にも影響します。検索エンジンは、末尾スラッシュの有無を別ページとして扱うことが多いためです。この違いが、重複コンテンツ、インデックスの問題、正規 URL の混乱につながることがあります。

assets.html_handling 設定 は、HTML コンテンツ向けリクエストのリダイレクトとリライトを決めます。正規 URL のパターン、つまり Cloudflare が HTML を配信する場所と、非正規 URL のリダイレクト先を指定します。

次のディレクトリ構成を例にします。

  • dist
    • file.html
    • folder
      • index.html

自動の末尾スラッシュ(既定)

通常、望ましい動作になります。個別ファイル(例: foo.html)は末尾スラッシュ なし で配信され、フォルダーの index ファイル(例: foo/index.html)は末尾スラッシュ あり で配信されます。

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-09-20",
	"assets": {
		"directory": "./dist/",
		"html_handling": "auto-trailing-slash"
	}
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-09-20"

[assets]
directory = "./dist/"
html_handling = "auto-trailing-slash"

着信リクエストに応じて、次のアセットが配信されます。

着信リクエスト 応答 配信されるアセット
/file 200 /dist/file.html
/file.html 307 to /file -
/file/ 307 to /file -
/file/index 307 to /file -
/file/index.html 307 to /file -
/folder 307 to /folder/ -
/folder.html 307 to /folder -
/folder/ 200 /dist/folder/index.html
/folder/index 307 to /folder -
/folder/index.html 307 to /folder -

末尾スラッシュを強制する

代わりに、末尾スラッシュを強制できます(force-trailing-slash)。

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-09-20",
	"assets": {
		"directory": "./dist/",
		"html_handling": "force-trailing-slash"
	}
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-09-20"

[assets]
directory = "./dist/"
html_handling = "force-trailing-slash"

着信リクエストに応じて、次のアセットが配信されます。

着信リクエスト 応答 配信されるアセット
/file 307 to /file/ -
/file.html 307 to /file/ -
/file/ 200 /dist/file.html
/file/index 307 to /file/ -
/file/index.html 307 to /file/ -
/folder 307 to /folder/ -
/folder.html 307 to /folder/ -
/folder/ 200 /dist/folder/index.html
/folder/index 307 to /folder/ -
/folder/index.html 307 to /folder/ -

末尾スラッシュを落とす

または、末尾スラッシュを落とせます(drop-trailing-slash)。

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-09-20",
	"assets": {
		"directory": "./dist/",
		"html_handling": "drop-trailing-slash"
	}
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-09-20"

[assets]
directory = "./dist/"
html_handling = "drop-trailing-slash"

着信リクエストに応じて、次のアセットが配信されます。

着信リクエスト 応答 配信されるアセット
/file 200 /dist/file.html
/file.html 307 to /file -
/file/ 307 to /file -
/file/index 307 to /file -
/file/index.html 307 to /file -
/folder 200 /dist/folder/index.html
/folder.html 307 to /folder -
/folder/ 307 to /folder -
/folder/index 307 to /folder -
/folder/index.html 307 to /folder -

HTML の扱いを無効にする

独自の要件がある場合は、組み込みの HTML 扱いを完全に無効にできます(none)。

{
	"name": "my-worker",
	// Set this to today's date
	"compatibility_date": "2026-09-20",
	"assets": {
		"directory": "./dist/",
		"html_handling": "none"
	}
}
name = "my-worker"
# Set this to today's date
compatibility_date = "2026-09-20"

[assets]
directory = "./dist/"
html_handling = "none"

着信リクエストに応じて、次のアセットが配信されます。

着信リクエスト 応答 配信されるアセット
/file not_found_handling に依存 not_found_handling に依存
/file.html 200 /dist/file.html
/file/ not_found_handling に依存 not_found_handling に依存
/file/index not_found_handling に依存 not_found_handling に依存
/file/index.html not_found_handling に依存 not_found_handling に依存
/folder not_found_handling に依存 not_found_handling に依存
/folder.html not_found_handling に依存 not_found_handling に依存
/folder/ not_found_handling に依存 not_found_handling に依存
/folder/index not_found_handling に依存 not_found_handling に依存
/folder/index.html 200 /dist/folder/index.html

役に立ちましたか?