没有www [SSL]重定向到域

时间:2016-03-09 19:41:45

标签: .htaccess

我想重定向到没有www的域名, 我在.htaccess文件中尝试了这些代码:

RewriteCond %{HTTP_HOST} ^(www\.example\.com)(:80)? [NC]
RewriteRule ^(.*) https://example.com/$1 [R=301,L]

以及

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

当我输入www.mysite.com时,我输入了https:www.mysite.com我收到了这个错误:

An error occurred during a connection to www.example.com. 
Peer reports it experienced an internal error. (Error code: 
ssl_error_internal_error_alert) 

我的错误是什么?

更新:我已经拥有有效的SSL证书。 我使用此代码重定向到HTTPS:

.htaccess文件的顶部:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码:

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

这将重定向:

在测试之前清除浏览器的缓存。

相关问题