コンテンツにスキップ

以下のを探索してください。

59 examples

AVIF画像の圧縮を無効にする

AVIF画像の圧縮を無効にするルールを作成します。 リクエストで指定されたコンテンツタイプまたはファイル拡張子に基づいています。

Compression Rules

Brotli圧縮を無効にする

指定されたゾーンのすべての受信リクエストに対してBrotli圧縮を無効にする圧縮ルールを作成します。

圧縮ルール

URIパスとホストヘッダーの変更

受信リクエストのURIパスと`Host`ヘッダーを調整する方法を学びます。この例では、同時に変更を達成するためにTransform RulesとOrigin Rulesの両方を使用する方法を示します。

Transform Rules, Origin Rules

URLパスからロケールを削除する

ロケール情報を含む古いURL形式から新しいURL形式に訪問者をリダイレクトするためのリダイレクトルールを作成します。

Redirect Rules

WWWからルートへのリダイレクト

WWWサブドメインからルート(「エイペックス」または「ネイキッド」ドメインとも呼ばれる)へのHTTPSリクエストを転送するリダイレクトルールを作成します。

Redirect Rules

デバッグログ

エラー応答にデバッグ情報を送信してロギングサービスに送る。

スニペット

ブログアーカイブのURLを書き換える

URL形式`/posts/--

-`を新しい形式`/posts/<YYYY>/<MM>/<DD>/<TITLE>`に書き換える変換ルールを作成します。</p> <p><strong>Transform Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="スニペット" data-goal="認証" data-operation="リクエストの修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/snippets/examples/auth-with-headers/">ヘッダーによる認証</a> </p> <div class="body astro-rcyev3ef"><p>ヘッダー内の既知の事前共有キーに基づいてリクエストを許可または拒否します。 これは<a href="https://ja.cloudflare.opendocs.dev/workers/runtime-apis/web-crypto/">WebCrypto API</a>の代わりになることを意図していません。</p> <p><strong>スニペット</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="スニペット" data-goal="ヘッダーを管理する" data-operation="リクエストの修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/snippets/examples/bot-data-to-origin/">ボット管理情報をオリジンに送信する</a> </p> <div class="body astro-rcyev3ef"><p>[ボット](/bots/)情報をオリジンに送信します。<a href="https://ja.cloudflare.opendocs.dev/bots/reference/bot-management-variables/">ボット管理変数</a>を参照して、利用可能なフィールドの完全なリストを確認してください。</p> <p><strong>スニペット</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="スニペット" data-goal="ルーティング" data-operation="リダイレクト"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/snippets/examples/bulk-redirect-map/">マップオブジェクトに基づくバルクリダイレクト</a> </p> <div class="body astro-rcyev3ef"><p>マッピングされたオブジェクトに基づいて、リクエストのURLに対して特定のURLにリクエストをリダイレクトします。</p> <p><strong>スニペット</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Redirect Rules"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/url-forwarding/examples/perform-mobile-redirects/">モバイルリダイレクトを実行する</a> </p> <div class="body astro-rcyev3ef"><p>モバイルデバイスを使用している訪問者を別のホスト名にリダイレクトするルールを作成します。</p> <p><strong>Redirect Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="スニペット" data-goal="認証" data-operation="リクエストの修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/snippets/examples/signing-requests/">リクエストに署名する</a> </p> <div class="body astro-rcyev3ef"><p>HMACおよびSHA-256アルゴリズムを使用して署名されたリクエストを検証するか、403を返します。</p> <p><strong>スニペット</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Transform Rules" data-operation="リクエスト修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/transform/examples/remove-request-header/">リクエストヘッダーを削除する</a> </p> <div class="body astro-rcyev3ef"><p>リクエストから `cf-connecting-ip` HTTP ヘッダーを削除するためのリクエストヘッダー修正ルール (Transform Rules の一部) を作成します。</p> <p><strong>Transform Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="スニペット" data-goal="その他" data-operation="リクエストの修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/snippets/examples/remove-query-strings/">リクエストをオリジンに送信する前にクエリ文字列を削除する</a> </p> <div class="body astro-rcyev3ef"><p>リクエストをオリジンに渡す前に特定のクエリ文字列を削除します。</p> <p><strong>スニペット</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Redirect Rules"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/url-forwarding/examples/redirect-root-to-www/">ルートからWWWへのリダイレクト</a> </p> <div class="body astro-rcyev3ef"><p>ルート(「エイペックス」または「ネイキッド」ドメインとも呼ばれる)からWWWサブドメインへのHTTPSリクエストを転送するリダイレクトルールを作成します。</p> <p><strong>Redirect Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="スニペット" data-goal="ヘッダーの管理" data-operation="レスポンスの修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/snippets/examples/remove-response-headers/">レスポンスヘッダーの削除</a> </p> <div class="body astro-rcyev3ef"><p>特定の名前で始まるすべてのヘッダーをレスポンスから削除します。</p> <p><strong>スニペット</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Transform Rules" data-operation="レスポンス修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/transform/examples/remove-response-header/">レスポンスヘッダーを削除する</a> </p> <div class="body astro-rcyev3ef"><p>レスポンスから`cf-connecting-ip` HTTPヘッダーを削除するためのレスポンスヘッダー修正ルール(Transform Rulesの一部)を作成します。</p> <p><strong>Transform Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Redirect Rules"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/url-forwarding/examples/redirect-all-another-domain/">一つのドメインから別のドメインへのリクエストをリダイレクトする</a> </p> <div class="body astro-rcyev3ef"><p>異なるドメインへのリダイレクトルールを作成し、すべての機能を維持しますが、廃止されたHTTPサービス(ポート80)は除きます。</p> <p><strong>Redirect Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Redirect Rules"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/url-forwarding/examples/redirect-all-country/">一国からドメインへのリクエストをリダイレクト</a> </p> <div class="body astro-rcyev3ef"><p>イギリスからのすべてのウェブサイト訪問者を異なるドメインにリダイレクトするリダイレクトルールを作成し、同じパスで現在の機能を維持します。</p> <p><strong>Redirect Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="スニペット" data-goal="ロギング" data-operation="応答の修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/snippets/examples/return-incoming-request-properties/">受信リクエストに関する情報を返す</a> </p> <div class="body astro-rcyev3ef"><p>Cloudflareのグローバルネットワークによって提供された、受信リクエストに関する情報で応答します。</p> <p><strong>スニペット</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="スニペット" data-goal="A/Bテスト" data-operation="クッキー操作,URLの書き換え"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/snippets/examples/ab-testing-same-url/">同一URLの直接アクセスによるA/Bテスト</a> </p> <div class="body astro-rcyev3ef"><p>クッキーに基づいて提供されるレスポンスを制御することでA/Bテストを設定します。</p> <p><strong>スニペット</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="スニペット" data-goal="ローカリゼーション" data-operation="リダイレクト"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/snippets/examples/country-code-redirect/">国コードリダイレクト</a> </p> <div class="body astro-rcyev3ef"><p>訪問者のヘッダーにある国コードに基づいてレスポンスをリダイレクトします。</p> <p><strong>スニペット</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Redirect Rules"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/url-forwarding/examples/redirect-country-subdomains/">地元の訪問者を特定のサブドメインにリダイレクトする</a> </p> <div class="body astro-rcyev3ef"><p>イギリスとフランスの訪問者を `example.com` ウェブサイトのルートパス (`/`) からそれぞれのローカライズされたサブドメイン `<a href="https://gb.example.com%5C%60">https://gb.example.com\`</a> と `<a href="https://fr.example.com%5C%60">https://fr.example.com\`</a> にリダイレクトするルールを作成します。</p> <p><strong>Redirect Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="圧縮ルール"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/compression-rules/examples/only-brotli-url-path/">特定のパスに対してBrotli圧縮のみを使用する</a> </p> <div class="body astro-rcyev3ef"><p>特定のURIパスに対してBrotliを唯一のサポートされる圧縮アルゴリズムとして設定する圧縮ルールを作成します。</p> <p><strong>圧縮ルール</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="スニペット" data-goal="ヘッダーの管理" data-operation="レスポンスの修正,クッキーの操作"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/snippets/examples/override-set-cookies-value/">特定の値で Set-Cookie ヘッダーを上書きする</a> </p> <div class="body astro-rcyev3ef"><p>特定の `Set-Cookie` ヘッダーを取得し、特定の値で更新します。</p> <p><strong>スニペット</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Transform Rules" data-operation="Rewrite URL"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/transform/examples/rewrite-welcome-for-countries/">特定の国の訪問者向けにページパスを再書き込み</a> </p> <div class="body astro-rcyev3ef"><p>特定の国の訪問者向けにウェルカムページのパスを再書き込みするための2つのURL再書き込みルールを作成します。</p> <p><strong>Transform Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Transform Rules" data-operation="リクエスト修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/transform/examples/add-request-header-bot-score/">現在のボットスコアを持つリクエストヘッダーを追加する</a> </p> <div class="body astro-rcyev3ef"><p>リクエストヘッダー修正ルール(Transform Rulesの一部)を作成して、現在のボットスコアを持つ`X-Bot-Score` HTTPヘッダーをリクエストに追加します。</p> <p><strong>Transform Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Transform Rules" data-operation="レスポンス修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/transform/examples/set-response-header-bot-score/">現在のボットスコアを持つレスポンスヘッダーを設定する</a> </p> <div class="body astro-rcyev3ef"><p>レスポンスに現在のボットスコアを設定する`X-Bot-Score` HTTPヘッダーを作成するためのレスポンスヘッダー修正ルール(Transform Rulesの一部)。</p> <p><strong>Transform Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Cloud Connector"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/cloud-connector/examples/route-images-to-s3/">画像をS3バケットにルーティングする</a> </p> <div class="body astro-rcyev3ef"><p>URIパスが`/images`で始まるリクエストをCloud Connectorを使用して特定のAWS S3バケットにルーティングします。</p> <p><strong>Cloud Connector</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Redirect Rules"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/url-forwarding/examples/redirect-all-different-hostname/">異なるホスト名へのリクエストをリダイレクト</a> </p> <div class="body astro-rcyev3ef"><p>\<code>smallshop.example.com\</code>へのすべてのリクエストをHTTPSを使用して異なるホスト名にリダイレクトするリダイレクトルールを作成し、元のパスとクエリ文字列を保持します。</p> <p><strong>Redirect Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="スニペット" data-goal="ルーティング" data-operation="リダイレクト"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/snippets/examples/bots-to-honeypot/">疑わしいボットをハニーポットに送信する</a> </p> <div class="body astro-rcyev3ef"><p>[ボットスコアフィールド](/workers/runtime-apis/request/#incomingrequestcfproperties)を使用してボットをハニーポットに送信します。</p> <p><strong>スニペット</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="スニペット" data-goal="その他" data-operation="リクエストの修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/snippets/examples/slow-suspicious-requests/">疑わしいリクエストを遅延させる</a> </p> <div class="body astro-rcyev3ef"><p>あなたが疑わしいと考えるルールに一致する受信リクエストに使用する遅延を定義します。</p> <p><strong>スニペット</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Transform Rules" data-operation="Rewrite URL"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/transform/examples/rewrite-moved-section/">移動したウェブサイトのセクションのパスをリライトする</a> </p> <div class="body astro-rcyev3ef"><p>\<code>/blog/<PATH>\</code>以下のすべてを`/marketing/<PATH>`に書き換えるリライトURLルールを作成します。</p> <p><strong>Transform Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Redirect Rules"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/url-forwarding/examples/redirect-admin-https/">管理エリアのリクエストをHTTPSにリダイレクトする</a> </p> <div class="body astro-rcyev3ef"><p>\<code>store.example.com\</code>の管理エリアへのリクエストをHTTPSにリダイレクトするルールを作成し、元のパスとクエリ文字列を保持します。</p> <p><strong>Redirect Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Transform Rules" data-operation="Rewrite URL"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/transform/examples/rewrite-several-url-different-url/">複数のURLセグメントを持つ画像パスの書き換え</a> </p> <div class="body astro-rcyev3ef"><p>\<code>/images/<FOLDER1>/<FOLDER2>/<FILENAME>\</code> へのリクエストを `/img/<FILENAME>` に書き換えるリライトルールを作成します。</p> <p><strong>Transform Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Redirect Rules"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/url-forwarding/examples/redirect-new-url/">訪問者を新しいページURLにリダイレクトする</a> </p> <div class="body astro-rcyev3ef"><p>`/contact-us/` からページの新しいパス `/contacts/` へのリダイレクトルールを作成します。</p> <p><strong>Redirect Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Transform Rules" data-operation="レスポンス修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/transform/examples/set-response-header-static-value/">静的値でレスポンスヘッダーを設定する</a> </p> <div class="body astro-rcyev3ef"><p>レスポンスに静的値(`Cloudflare`)の`X-Bot-Score` HTTPヘッダーを設定するためのレスポンスヘッダー修正ルール(Transform Rulesの一部)を作成します。</p> <p><strong>Transform Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Transform Rules" data-operation="リクエスト修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/transform/examples/add-request-header-static-value/">静的値を持つリクエストヘッダーを追加</a> </p> <div class="body astro-rcyev3ef"><p>リクエストに静的値(`Cloudflare`)を持つ`X-Source` HTTPヘッダーを追加するためのリクエストヘッダー修正ルール(Transform Rulesの一部)を作成します。</p> <p><strong>Transform Rules</strong></p> </div> </article> <article class="card sl-flex astro-rcyev3ef" data-example data-products="Transform Rules" data-operation="レスポンス修正"> <p class="title sl-flex astro-rcyev3ef"> <a class="title astro-rcyev3ef" href="/rules/transform/examples/add-response-header-static-value/">静的値を持つレスポンスヘッダーを追加</a> </p> <div class="body astro-rcyev3ef"><p>レスポンスに静的値(`cookiename=value`)を持つ`set-cookie` HTTPヘッダーを追加するレスポンスヘッダー修正ルール(Transform Rulesの一部)を作成します。</p> <p><strong>Transform Rules</strong></p> </div> </article> </div> </div> </div> <footer class="sl-flex astro-3yyafb3n"> <div class="meta sl-flex astro-3yyafb3n"> <a href="https://github.com/cloudflare/cloudflare-docs/edit/production/src/content/docs/rules/examples.mdx" class="sl-flex astro-eez2twj6"><svg aria-hidden="true" class="astro-eez2twj6 astro-c6vsoqas" width="16" height="16" viewBox="0 0 24 24" fill="currentColor" style="--sl-icon-size: 1.2em;"><path d="M22 7.24a1 1 0 0 0-.29-.71l-4.24-4.24a1 1 0 0 0-1.1-.22 1 1 0 0 0-.32.22l-2.83 2.83L2.29 16.05a1 1 0 0 0-.29.71V21a1 1 0 0 0 1 1h4.24a1 1 0 0 0 .76-.29l10.87-10.93L21.71 8c.1-.1.17-.2.22-.33a1 1 0 0 0 0-.24v-.14l.07-.05ZM6.83 20H4v-2.83l9.93-9.93 2.83 2.83L6.83 20ZM18.17 8.66l-2.83-2.83 1.42-1.41 2.82 2.82-1.41 1.42Z"/></svg> ページを編集</a> </div> </footer> <div class="items-center flex flex-wrap"><a href="https://dash.cloudflare.com/?to=/:account/:zone/rules" class="mx-2 my-2 text-xs text-black dark:text-white decoration-accent-600 dark:decoration-accent-200"><span>Cloudflare Dashboard</span></a><a href="https://discord.cloudflare.com" class="mx-2 my-2 text-xs text-black dark:text-white decoration-accent-600 dark:decoration-accent-200"><span>Discord</span></a><a href="https://community.cloudflare.com" class="mx-2 my-2 text-xs text-black dark:text-white decoration-accent-600 dark:decoration-accent-200"><span>Community</span></a><a href="https://www.cloudflare.com/learning/" class="mx-2 my-2 text-xs text-black dark:text-white decoration-accent-600 dark:decoration-accent-200"><span>Learning Center</span></a><a href="/support/contacting-cloudflare-support/" class="mx-2 my-2 text-xs text-black dark:text-white decoration-accent-600 dark:decoration-accent-200"><span>Support Portal</span></a><div class="mx-2 my-2 text-xs text-black dark:text-white underline decoration-accent-600 dark:decoration-accent-200"><script src="https://ot.www.cloudflare.com/public/vendor/onetrust/scripttemplates/otSDKStub.js" type="text/javascript" charset="UTF-8" data-domain-script="b1e05d49-f072-4bae-9116-bdb78af15448"></script><script type="text/javascript">function OptanonWrapper() {}</script><span class="DocsFooter--content-additional-wrapper astro-hwxmvrii"> <!-- OneTrust Cookies Settings button start --> <a role="button" id="ot-sdk-btn" class="ot-sdk-show-settings astro-hwxmvrii">Cookie Settings</a> <!-- OneTrust Cookies Settings button end --> </span> </div></div> </div> </div> </main> </div> </div> </div> </div> </body></html>