htaccess将通配符子域重定向到https(包括www)


htaccess Redirect Wildcard Subdomains to https (Including www)

当前我的htaccess文件将所有子域的非https请求重定向到https。。。除了www请求。即http://subdomain.example.com被重定向到https://subdomain.example.com(这是正确的),但www.subdomain.example.com被重定向到了https://www.subdomain.example.com(不正确)。这是我的.htaccess代码:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>
    RewriteEngine On
    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    # Trying to redirect to https
    RewriteCond %{HTTPS} off
    RewriteCond %{SERVER_PORT} !=443
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

尝试更改此项:

RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]

RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(?:www'.|)(.+'.example'.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]