如何将所有子域重定向到 https

How can I redirect all Subdomains to https

你好,应该向 htaccess 添加什么以将所有子域重定向到 https webmail.example.com?

<IfModule mod_rewrite.c>

  RewriteOptions inherit
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule . /index.html [L]

</IfModule>

Header set content-Security-Policy: upgrade-insecure-requests
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

您已经有一个将所有内容(任何 domain/subdomain)重定向到 HTTPS 的规则。因此,如果这不起作用,则:

  1. 这个子域 不是 指向文件系统的同一区域(所以这个 .htaccess 文件不适用,指令被忽略) .

  2. 这些指令没有做任何事情,即。 mod_rewrite 或 .htaccess 覆盖未在您的服务器上启用。

由于您在 .htaccess 文件中有一个“前端控制器”模式(last 规则),我假设它已成功用于为您的网站提供服务?如果是这样,那么 .htaccess 和 mod_rewrite 似乎已启用并正在工作。

那似乎离开了#1。 在哪种情况下 webmail 子域指向文件系统的这个区域?

webmail 子域是您创建的还是您的托管帐户的一部分? webmail 是 cPanel 使用的常见子域(并且您已经标记了您的问题 cPanel)。在这种情况下,此子域可能指向文件系统的一个完全不同的区域,并且不受您的控制。