【问题标题】:.htaccess redirect from non-www http subfolder to www https subfolder.htaccess 从非 www http 子文件夹重定向到 www https 子文件夹
【发布时间】:2020-07-23 10:20:09
【问题描述】:

我使用这个简单的代码将非 www http 重定向到 www https

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

它成功地将http://example.com 重定向到https://www.example.com。 但是当我尝试访问http://example.com/somefolder 时,它并没有被重定向。我在这里错过了一些语法吗?还是别的什么?

【问题讨论】:

    标签: .htaccess redirect https subdirectory


    【解决方案1】:

    将 %{REQUEST_URI} 更改为 /$1(规则中的第一个匹配项 .*)

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

    或修改最后一个规则模式:

    RewriteEngine on
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^example.com$
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-26
      • 1970-01-01
      相关资源
      最近更新 更多