【问题标题】:Redirect www to non www with SSL使用 SSL 将 www 重定向到非 www
【发布时间】:2016-11-26 20:44:59
【问题描述】:

我看过很多关于重写的文章,但我有一个问题。

example.com => https://example.com(好的)
www.example.com => https://example.com(好的)
https://example.com => https://example.com(好的)
https://www.example.com => https://example.com(失败)

他尝试了几种论坛解决方案,但我遇到了同样的问题。现在我的 htaccess 是:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.[^.]+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]
</IfModule>

【问题讨论】:

    标签: .htaccess redirect ssl


    【解决方案1】:

    你可以使用:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
    </IfModule>
    

    在您的代码中,第二个测试没有使用 http 执行,%1 不正确。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-09-11
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      • 2010-12-01
      • 2016-04-02
      • 2014-11-24
      • 2016-06-06
      相关资源
      最近更新 更多