Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 重定向到不带www的域[SSL]_.htaccess - Fatal编程技术网

.htaccess 重定向到不带www的域[SSL]

.htaccess 重定向到不带www的域[SSL],.htaccess,.htaccess,我想重定向到没有www的域, 我在.htaccess文件中尝试了以下代码: RewriteCond %{HTTP_HOST} ^(www\.example\.com)(:80)? [NC] RewriteRule ^(.*) https://example.com/$1 [R=301,L] RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://example.com/$1 [R=301,L] 而且

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

RewriteCond %{HTTP_HOST} ^(www\.example\.com)(:80)? [NC]
RewriteRule ^(.*) https://example.com/$1 [R=301,L]
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
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:

在my
.htaccess
文件的顶部:

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

您可以使用以下代码:

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


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

您是否有ssl证书?是且100%确定其有效性您应该检查error.log和access.log以了解更多信息谢谢。但是我想重定向到https,我有用于SSL的代码
RewriteCond%{SERVER_PORT}80
@Anoano我的代码从非SSL重定向到SSL。你试过这个吗?