【问题标题】:htaccess redirect all subdomains to https except wwwhtaccess 将所有子域重定向到 https,除了 www
【发布时间】:2011-06-10 15:27:31
【问题描述】:

我想将所有子域(我在 apache 虚拟主机中设置通配符子域)重定向到 https,如果是 http,则除 www.domain.com 之外的所有子域

非常感谢任何想法。

这是我目前所拥有的:

# Redirect subdomains to https
#RewriteCond %{HTTPS} off
#RewriteCond %{HTTP_HOST} ^(*)\. [NC]
#RewriteCond %{HTTP_HOST} !^(www)\. [NC]
#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

谢谢!

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    在您的 .htaccess 文件中尝试此代码:

    Options +FollowSymlinks -MultiViews
    RewriteEngine On
    
    RewriteCond %{SERVER_PORT} =80
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    

    【讨论】:

      【解决方案2】:

      这应该对你有帮助:

      RewriteCond %{HTTP_HOST} !^(www\.)localhost.com$
      RewriteCond %{HTTP_HOST} ^(.*?)\.localhost.com$
      RewriteCond %{HTTPS} !=on
      RewriteRule ^(.*?)$ https://%{HTTP_HOST} [nc]
      

      第一RewriteCond:如果网站不以www开头

      第二个RewriteCond:获取任意子域

      第三个RewriteCond:检查 https 是否已经在请求的 url 中

      RewriteRule: 重定向到 https 版本的站点

      【讨论】:

        猜你喜欢
        • 2017-04-22
        • 1970-01-01
        • 2018-06-02
        • 1970-01-01
        • 2015-05-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多