Skip to content

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

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

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

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

この例では、WWW サブドメイン(www.example.com)からルートドメイン(example.com)へ HTTPS リクエストを転送し、元のパスとクエリ文字列は維持するリダイレクトルールを作成します。

When incoming requests match

  • Wildcard pattern
    • Request URL: https://www.*

Then

  • Target URL: https://${1}
  • Status code: 301
  • Preserve query string: Enabled

このルールは、www. サブドメインからの HTTPS リクエストだけをルートドメインへリダイレクトし、その他のリクエスト(HTTP や非 WWW など)は変更しません。

たとえば、このリダイレクトルールは次のリダイレクトを行います。

リクエスト URL ターゲット URL ステータスコード
https://www.example.com/products/ https://example.com/products/ 301
https://www.store.example.com/products/ https://store.example.com/products/ 301
https://store.example.com/products/ (変更なし) 該当なし
https://www.example.com/admin/?logged_out=true https://example.com/admin/?logged_out=true 301
http://www.example.com/?all_items=true (変更なし) 該当なし
http://example.com/admin/ (変更なし) 該当なし

役に立ちましたか?