将所有http流量重定向到https

时间:2014-03-20 16:18:08

标签: .htaccess mod-rewrite redirect ssl https

我遵循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进行浏览(绿色挂锁让人们感到安全,这很有趣)。

1 个答案:

答案 0 :(得分:0)

如果以这种方式交换规则,这应该有用

<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>