将HTTPredirect到HTTPS Apache2

即时通讯尝试将httpredirect到https。 我find了很多答案,但没有为我工作。 我不知道为什么,也许它的apache2configuration错误? 我试着在.htaccess中也没有任何反应。

只是这个错误:

错误的请求你的浏览器发送了一个这个服务器无法理解的请求。 原因:您正在向使用SSL的服务器端口说纯HTTP。 请使用HTTPSscheme访问此URL。

这是我的虚拟主机文件。

#Redirect HTTP TO HTTPS RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L] #VHOSTS <VirtualHost *:443> Servername www.latoya.eu ServerAlias latoya.eu www.latoya.eu Documentroot /var/www/latoya ErrorLog /path/to/log/error.log CustomLog /path/to/log/access.log combined SSLEngine on SSLCertificateFile /path/to/ssl/files/pem.crt SSLCertificateKeyFile /path/to/ssl/files/private.key SSLCertificateChainFile /path/to/ssl/files/pem.ca-bundle </VirtualHost> <VirtualHost *:443> Servername board.latoya.eu Documentroot /var/www/latoya ErrorLog /path/to/log/error.log CustomLog /path/to/log/access.log combined SSLEngine on SSLCertificateFile /path/to/ssl/files/pem.crt SSLCertificateKeyFile /path/to/ssl/files/private.key SSLCertificateChainFile /path/to/ssl/files/pem.ca-bundle </VirtualHost> <VirtualHost *:443 *:80> Servername secure.latoya.eu Documentroot /var/www/latoya ErrorLog /path/to/log/error.log CustomLog /path/to/log/access.log combined SSLEngine on SSLCertificateFile /path/to/ssl/files/pem.crt SSLCertificateKeyFile /path/to/ssl/files/private.key SSLCertificateChainFile /path/to/ssl/files/pem.ca-bundle </VirtualHost> <VirtualHost *:80 *:443> Servername static.kritzelpixel.com Documentroot /var/www/static.kritzelpixel.com ErrorLog /path/to/log/error.log CustomLog /path/to/log/access.log combined SSLCertificateFile /path/to/ssl/files/pem.crt SSLCertificateKeyFile /path/to/ssl/files/private.key SSLCertificateChainFile /path/to/ssl/files/pem.ca-bundle </VirtualHost> 

使用“VirtualHost *:80 *:443”或相同的虚拟主机标签中的相反是完全不正确的,因为一个虚拟主机不能同时SSL和SSL。

Apache HTTPD并没有因此而痛苦,因为你可以在同一个虚拟主机上使用不同的端口,但是这当然不是设计成一个SSL端口和一个非SSL端口。

所以我的建议是你正确的配置看起来很健全,即分别具有特定的虚拟主机*:80和虚拟主机*:443。

在VirtualHost *:80条目中,您可以使用特定的主机名重定向/ https://example.com/ ,将您的情况从80重定向到443,而无需使用mod_rewrite。

重定向到SSL mod_rewrite是不需要和矫枉过正的。

简述:

 <VirtualHost *:80> serverName example.com Redirect / https://example.com/ </VirtualHost> <VirtualHost *:443> serverName example.com SSLEngine on #other directives here </VirtualHost> 

如果他们有不同的配置,就和其余的名字一样。