Php 重定向http://和http://www 到https://www 不影响网站上的其他子域

Php 重定向http://和http://www 到https://www 不影响网站上的其他子域,php,apache,.htaccess,mod-rewrite,redirect,Php,Apache,.htaccess,Mod Rewrite,Redirect,我的网站上的htaccess有两个问题 重定向 => => => 我在.htaccess中有: RewriteCond %{HTTP_HOST} !^$ RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTPS} off RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE] 除了在Mozilla Firefox上尝试访问example.com并将其重写为 我不

我的网站上的htaccess有两个问题

  • 重定向
  • =>

    =>

    =>

    我在.htaccess中有:

    RewriteCond %{HTTP_HOST} !^$
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    
    除了在Mozilla Firefox上尝试访问example.com并将其重写为

  • 我不希望htaccess影响我站点上的其他子域。我不想要的例子 被重定向

  • 我的网站支持通配符子域,因此我不会重写所有子域。

    我想这就是您要找的:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^(example\.com)$ [NC]
    RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
    
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    

    我不知道你提到的mozilla例外。可能是缓存问题?您需要更仔细地查看日志文件,也许您必须启用重写日志,以查看重写引擎中到底发生了什么…

    感谢您的回复。它没有重定向到Google ChromeI上,简化了规则。mozilla问题在一段时间后得到解决。