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

Php htaccess将通配符子域重定向到https(包括www),php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,当前,我的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> <If

当前,我的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>

选项-多视图
重新启动发动机
#重定向尾部斜杠。。。
重写规则^(.*)/$/$1[L,R=301]
#正在尝试重定向到https
重写条件%{HTTPS}关闭
重写cond%{SERVER\u PORT}=443
重写规则^https://%{HTTP_HOST}%{REQUEST_URI}[L,NE,R=301]
#处理前控制器。。。
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^index.php[L]
尝试更改此选项:

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


阅读注释
#尝试重定向到https
下的三行,如果https关闭并且我们没有在端口443上提供服务,则重定向到主机(http://和trailing/after.com之间的所有内容)。你实际上是使用他们为主机放置的任何内容将所有内容重定向到HTTPS。这是正确的,但这并没有回答我的问题。如何修改此代码以将www重定向到https?对于htaccess,我是一个初学者。有了这个变化,
subdomain.example.com
被重定向到
https://www.subdomain.example.com
www.subdomain.example.com
仍被重定向到“.@sterfy68”,如您所见,@sterfy68是否已清除浏览器的缓存?这些规则很有效。
RewriteCond %{HTTPS} off
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(?:www\.|)(.+\.example\.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]