【问题标题】:htaccess for redirecting non-www to www while preserving http & httpshtaccess 用于将非 www 重定向到 www,同时保留 http 和 https
【发布时间】:2011-09-25 09:41:23
【问题描述】:

我的网站刚刚获得了 EV SSL 证书。在过去,我使用 htaccess 将非 www 请求重定向到 www - 它运行良好。

但是现在,如果我请求一个 https 页面,我最终会(通过 htaccess 重定向)在 http 版本上。

我需要 htaccess 像这样重定向:非 www 重定向到 www,同时保留 http 或 https

这是我现在使用的 htaccess 文件:

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

它工作不正常。 https 请求被重定向到 http。

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    试试这个:

    Options +FollowSymLinks 
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
    RewriteCond %{HTTPS} =on
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301,QSA]
    RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
    RewriteCond %{HTTPS} !=on
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301,QSA]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-01
      • 2018-09-26
      • 2018-11-12
      • 2014-12-16
      相关资源
      最近更新 更多