【问题标题】:Cloudflare SSL Page rulesCloudflare SSL 页面规则
【发布时间】:2026-01-17 03:50:01
【问题描述】:

我正在尝试在 Cloudflare 上创建一些页面规则,这将始终强制任何 url 使用 https:// 而不是 http://。

我尝试了各种解决方案,但似乎无法正确解决。我要么以无限循环结束,要么以 http:// 使用。所以我希望有人能指出我正确的方向。

我想要的是将以下所有 URL 重定向到使用 https://:

  • example.com
  • app.example.com
  • user.app.example.com
  • www.example.com
  • example.com/test
  • app.example.com/test
  • user.app.example.com/test
  • www.example.com/test

我已经尝试了以下所有规则:

  1. *.example.com/* Should forward to https://$1.example.com/$2
  2. example.com/* Should forward to https://example.com/$2
  3. *example.com/* Should forward to https://$1example.com/$2
  4. http://*example.com/* Should always use HTTPS

同时使用 #1 和 #2 会导致无限重定向循环。 #3也是如此。 4 号适用于“example.com”,但当我尝试访问“app.example.com”时什么也不做,

有人可以帮我解决这些页面规则吗?

【问题讨论】:

    标签: ssl https cloudflare


    【解决方案1】:

    您应该能够只使用以下页面规则:

    http://*example.com/* 和“始终使用 HTTPS”的“+ A 设置”

    您可以在此视频中看到演练:

    https://www.cloudflare.com/features-page-rules/harden-security/

    【讨论】:

      【解决方案2】:

      您可能会无限重定向,因为您没有明确将“http://”声明为模式的一部分。

      您需要 2x CloudFlare 页面规则(模式+规则的组合):

      页面规则 1:

      模式语法:

      http://example.com/*
      

      规则:

      “始终使用 https” 将其设为 ON

      页面规则2:

      模式语法:

      http://*.example.com/*
      

      规则:

      “始终使用 https” 将其设为 ON

      这也会传递 slug 和参数,即

      http://example.com/404?somevar=lala

      将重定向到

      https://example.com/404?somevar=lala

      但是您还应该注意:

      • 这将影响所有可能的子域,而不仅仅是您的明确列表
      • CloudFlare 不支持二级子域 foo.bar.example.com

      【讨论】:

        【解决方案3】:

        以下页面规则模式对我有用:

        http://example.com/

        http://example.com/*

        http://*.example.com/

        http://*.example.com/*

        始终使用 https:ON

        (您必须同时使用//* 来覆盖根路径和任何其他路径。)

        https://www.cloudflare.com/a/page-rules

        【讨论】: