我正在尝试使用RewriteEngine在Apache中设置SSL重定向,它将执行以下操作:
我的理由是,在启动之前,我正在开发一个使用免费SSL证书的项目。此证书涵盖基本域,但没有一个通配符子域,每次访问其中一个子域时,都需要绕过警告是很痛苦的。
编辑:我相信我离这里很近了,但是我仍然不能让HTTPS重定向到HTTP来正常工作。
RewriteEngine on
# Redirect domain and www to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} =mydomain.com [or]
RewriteCond %{HTTP_HOST} =www.mydomain.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect wildcard subdomains to HTTP
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$ [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]发布于 2014-02-04 20:30:32
弄明白了。通过将这些规则从网站可用/默认文件移到网站根目录中的.htaccess中,我能够正常工作。
RewriteEngine on
# Redirect domain and www to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} =mydomain.com [or]
RewriteCond %{HTTP_HOST} =www.mydomain.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect wildcard subdomains to HTTP
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$ [NC]
RewriteCond %{HTTP_HOST} !=www.mydomain.com
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]https://stackoverflow.com/questions/21560603
复制相似问题