我正在尝试将所有 foo.mydomain.com 请求重定向到 https://foo.mydomain.com.
我的虚拟主机包含这个:
<VirtualHost *:443>
ServerName foo.mydomain.com
# Indexes + root dir
DirectoryIndex index.html
DocumentRoot /home/web/foo.mydomain.com/htdocs
SSLEngine on
SSLCertificateFile /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key
SSLVerifyClient none
<IfModule mime.c>
AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl .crl
</IfModule>
# Logfiles
ErrorLog /home/web/foo.mydomain.com/logs/error.log
CustomLog /home/web/foo.mydomain.com/logs/access.log combined
</VirtualHost>
所以现在我尝试使用此 .htaccess 文件中的 mod_rewrite 将所有 http 请求重定向到 https:
Options FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://foo.mydomain.com
有人知道我做错了什么吗?预先感谢您!
在非 HTTPS 站点的 VirtualHost 配置中尝试以下操作。
即我的设置是:
<VirtualHost *:80>
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
.....
</VirtualHost>
这应该将所有传入的 HTTP 请求重定向到 HTTPS。然后在端口 443 的配置中你可以做任何你需要的事情。
注意:也应该在 htaccess 中工作。
希望有帮助。不确定“默认页面”是什么意思,但在标题中,代表太低,无法发表评论......
让我知道...
干杯
罗宾