将所有HTTP重定向到HTTPS

时间:2015-01-13 08:36:36

标签: apache .htaccess redirect https

我的网站上有SSL,并希望将我的所有http网页重定向到https 我在下面找到了一些内容并为www.yourdomain.com工作。

如果我还需要将所有yourdomain.com(没有www)转移到https我应该添加到htaccess的内容?谢谢!

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
<!-- Please put the redirect without www here, thanks-->

1 个答案:

答案 0 :(得分:0)

简单的Google搜索会显示数百个结果。例如,这official FAQ

RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context