【问题标题】:Redirect http to https and www to non-www?将http重定向到https,将www重定向到非www?
【发布时间】:2017-08-23 16:36:59
【问题描述】:

我在 Google 中搜索了这个,然后 检查了 50 多个帖子,但似乎没有一个有效。假设我有一个域 example.com。我想做的是重定向

http://www.example.com
https://www.example.com
http://example.com

到

https://example.com

谁能帮帮我?? 如有任何帮助,我们将不胜感激。

注意:我使用的是 cloudflare,我无权访问 conf 文件。我可以访问 .htaccess 文件。

EDIT1:我的 htaccess 看起来像

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

【问题讨论】:

  • 它不会重定向

标签: apache .htaccess ssl


【解决方案1】:

你可以试试这样的:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

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

【讨论】:

    【解决方案2】:

    您可以在 Cloudfare 中使用此规则:

    RewriteEngine On 
    
    RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"' [OR]
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]
    

    【讨论】:

      猜你喜欢
      • 2017-11-24
      • 2017-03-24
      • 2016-01-07
      • 2012-04-14
      • 2019-12-13
      • 1970-01-01
      • 2018-09-26
      • 2017-02-02
      • 1970-01-01
      相关资源
      最近更新 更多