【问题标题】:Redirect all traffic from nonwww to www and https to http将所有流量从非 www 重定向到 www 和 https 到 http
【发布时间】:2016-10-28 06:19:54
【问题描述】:

我在网上找到了所有组合,除了这个。如何以通用方式将所有流量重定向到“http://www.”?

这样就发生了:

domain.com --> http://www.domain.com
www.domain.com --> http://www.domain.com
https://domain.com/page --> http://www.domain.com/page

等等

提前感谢您的帮助!

【问题讨论】:

    标签: .htaccess redirect ssl https no-www


    【解决方案1】:

    所以你只需要使用:

    RewriteEngine On
    
    #Force WWW on everything
    RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
    
    #Check to see if HTTPS, if so, make HTTP
    RewriteCond %{HTTPS} on
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    这将强制一切使用 WWW 和 HTTP。

    【讨论】:

    • 谢谢,但https://www.example.com 不会重定向到http://www.example.comhttps://example.com 正确重定向到 http://www.example.com
    【解决方案2】:

    这边

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-23
      • 2018-09-26
      • 2015-05-01
      • 2012-05-30
      • 2020-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多