如何在 http 和 https 之间切换?我想通过 .htaccess 来处理
.htaccess
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(secure)\.([^\.]+\.[^\.]+)$ [NC]
RewriteRule ^(.*)$ https://%1.%2/$1 [L,R=301]
httpd配置文件
<VirtualHost *:80>
ServerName domain.com
ServerAlias *.domain.com
DocumentRoot /var/www/domain.com
</VirtualHost>
<VirtualHost *:443>
ServerName secure.domain.com
DocumentRoot /var/www/domain.com
SSLEngine on
SSLCertificateFile /var/ini/ssl/public.crt
SSLCertificateKeyFile /var/ini/ssl/private.key
SSLCACertificateFile /var/ini/ssl/intermediate.crt
</VirtualHost>
当请求时....
答案1
为什么不直接添加Redirect permanent / https://secure.domain.com/
到您的 *.80 虚拟主机?
或者如果你只想要http://secure.domain.com重定向,然后仅为该 ServerAlias 添加另一个虚拟主机。