【问题标题】:Redirecting ALL http traffic to https将所有 http 流量重定向到 https
【发布时间】:2014-04-27 15:41:48
【问题描述】:

我已遵循 this thread 的建议,该建议将对我的案例网站riverstreetflowerland.com 的所有请求重定向到 https 版本。

您可以点击进入网站上的其他页面并在 https 上查看该网站。但是,如果您获得指向主页以外页面的直接链接(如 http://riverstreetflowerland.com/about-us/),则 .htaccess 不会将您重定向到 https 版本,您将在访问主页之前以 http 浏览该站点。

这是我当前的 .htaccess 作为参考:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
</IfModule>

# END WordPress

我只需要 100% 的时间将网站重定向到并通过 https 浏览(有趣的是绿色挂锁让人们感到安全)。

【问题讨论】:

    标签: .htaccess mod-rewrite redirect ssl https


    【解决方案1】:

    如果您以这种方式交换规则,这应该可以工作

    <IfModule mod_rewrite.c>
    RewriteEngine On
    
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
    
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    

    【讨论】:

    • 在您的代码中,由于第一条规则(WordPress 重写调度程序/控制器的主要规则),从未达到重定向
    猜你喜欢
    • 2016-07-27
    • 2012-04-19
    • 2015-03-01
    • 1970-01-01
    • 2014-08-23
    • 2013-01-06
    • 2016-03-18
    • 2016-10-28
    • 1970-01-01
    相关资源
    最近更新 更多