htaccess - 重写规则SSL重定向到https:// www

时间:2015-09-07 06:37:25

标签: .htaccess ssl

我想要一个重写规则,将所有内容重定向到https://和www。

例如https://example.com应该转到https://www.example.com

这就是我所拥有的:

RewriteEngine On
RewriteCond %{SERVER_PORT} !=443
RewriteCond %{HTTP_HOST} ^(www\.)?DOMAIN\.com$ [NC]
RewriteRule ^(.*)$ "https\:\/\/www\.DOMAIN\.com\/$1" [R=301,L]

2 个答案:

答案 0 :(得分:0)

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

我经历过它,它对我有用。这是我从https://wiki.apache.org/httpd/RewriteHTTPToHTTPS

获得我的地方

答案 1 :(得分:0)

尝试:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^DOMAIN\.com$ [NC]
RewriteRule ^(.*)$ https://www.DOMAIN.com/$1 [NC,R,L]

这会将SSL非www(https://domain.com)重定向到(https://www.domain.com

如果您想将非ssl和非www(http://domain.com)重定向到(https://www.domain.com),请尝试:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^DOMAIN\.com$ [NC]
RewriteRule ^(.*)$ https://www.DOMAIN.com/$1 [NC,R,L]
相关问题