コンテンツにスキップ

サブドメインの管理

Cloudflareにドメインを追加し、ネームサーバーを更新したら、サブドメインを設定したい場合もあるでしょう。

ほとんどのサブドメインは、ウェブサイト全体の文脈の中で特定の目的を果たします。例えば、blog.example.comはあなたのブログ、support.example.comは顧客サポートポータル、store.example.comはあなたのeコマースサイトになるかもしれません。

サブドメインを作成する

ホストでサブドメインをすでに追加している場合は、そのサブドメイン(blogstore)に対応するDNS AまたはCNAMEレコードを作成してください。

リダイレクトの設定

サブドメインをルートドメインにリダイレクトする

Sometimes, you might want all traffic to a subdomain (www.example.com) to actually go to your apex domain (example.com).

  1. Create a proxied DNS A record for your subdomain. This record can point to any IP address since all traffic will be redirected prior to reaching the address.

    TypeNameIPv4 addressProxy status
    Awww192.0.2.1Proxied
  2. Create a Single Redirect to forward traffic from your subdomain to your apex domain.

When incoming requests match

Using the Expression Editor:
(http.request.full_uri contains "www.example.com")

Then

  • Type: Dynamic
  • Expression: concat("https://","example.com",http.request.uri.path)
  • Status code: 301

ルートドメインをサブドメインにリダイレクトする

Sometimes, you might want all traffic to your apex domain (example.com) to actually go to a subdomain (www.example.com).

  1. If you have already added that subdomain at your host, create a corresponding DNS A or CNAME record for that subdomain.

  2. Create a proxied DNS A record for your apex domain. This record can point to any IP address since all traffic will be redirected prior to reaching the address.

    TypeNameIPv4 addressProxy status
    A@192.0.2.1Proxied
  3. Create a Single Redirect to forward traffic from your apex domain to your subdomain.

When incoming requests match

Using the Expression Editor:
(lower(http.host) eq "example.com")

Then

  • Type: Dynamic
  • Expression: concat("https://","www.example.com",http.request.uri.path)
  • Status code: 301

サブドメインのSSL/TLS

If your main domain is using Cloudflare’s Universal SSL certificate, that certificate also covers all first-level subdomains (blog.example.com).

For deeper subdomains (dev.blog.example.com), use a different type of certificate.

サブドメインの動作をカスタマイズする

If you want to customize Cloudflare settings for individual subdomains, your approach will vary depending on your plan.

Enterprise customers can set up custom settings and access for a specific subdomain within Cloudflare with Subdomain support.

All other customers can set up subdomain-specific Configuration Rules or Page Rules to alter Cloudflare settings.

If you want a subdomain’s DNS settings managed totally outside of Cloudflare — meaning this subdomain can be managed by individuals without access to your Cloudflare account — refer to Delegating subdomains outside of Cloudflare.