将http重定向到https

时间:2015-06-17 21:23:28

标签: apache .htaccess redirect ssl https

我想将我的所有http流量重定向到https,目前在我的htaccess文件中,我有以下重定向我的http流量:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
</IfModule>

这会将我的所有非www重定向到www。确保覆盖所有基础的最佳方法是什么,这意味着重定向以下所有内容:

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

1 个答案:

答案 0 :(得分:1)

您可以在.htaccess文件中使用此功能。只需将example.com替换为您的域名,即可涵盖所有基础。

IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !^on
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
</IfModule>
相关问题