【问题标题】:Redirect non-www(http) and www(http) to https://www将非 www(http) 和 www(http) 重定向到 https://www
【发布时间】:2018-09-26 17:21:32
【问题描述】:

我正在尝试从非 www(http) 和 www(http) 重定向到 https://www 但它不起作用。需要以下工作。请帮忙

  1. http://example.com 重定向到 https://www.example.com
  2. http://www.example.com 重定向到 https://www.example.com

当前的 htaccess 文件

rewritecond %{http_host} ^example.com [nc]

rewriterule ^(.*)$ https://www.example.com/$1 [r=301,nc]

尝试以下规则

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

【问题讨论】:

  • 抱歉,这个问题在 SO 上已经被问和回答了大约 65836593659 次。您真的确定所有这些答案都没有帮助吗? 为什么不呢? 为什么第 65836593659 个答案会有所作为?

标签: .htaccess redirect https no-www


【解决方案1】:

你可以用这个:

RewriteEngine on

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-01
    • 2012-05-30
    • 2015-04-20
    • 2017-12-04
    • 1970-01-01
    • 2018-02-02
    相关资源
    最近更新 更多