【问题标题】:How to redirect to directory on root but using https如何重定向到根目录但使用 https
【发布时间】:2017-11-03 00:32:39
【问题描述】:

我最近添加了 ssl 并希望重定向到 https 但要重定向到子文件夹。

我应该如何将我的重定向修改为 https 而不仅仅是 http?

这是我目前在 .htaccess 文件中的内容

RewriteEngine on
RewriteCond %{HTTP_HOST} main\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^(.*)$ /directory/$1 [L]

【问题讨论】:

    标签: .htaccess ssl redirect mod-rewrite url-rewriting


    【解决方案1】:

    在重写规则之前,您需要为http -> https 添加额外的重定向规则:

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} main\.com [NC]
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    
    RewriteCond %{HTTP_HOST} main\.com [NC]
    RewriteCond %{REQUEST_URI} ^/$
    RewriteRule ^(.*)$ /directory/$1 [L]
    

    【讨论】:

      猜你喜欢
      • 2019-07-20
      • 2016-08-10
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 2013-05-12
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多