将流量重定向到 https 站点

将流量重定向到 https 站点

我们的邮件服务器中托管了多个虚拟电子邮件域。用户可以使用 webmail.example.com(这是第一个 apache 虚拟主机)来检查邮件,也可以使用 mail.THEIR-DOMAIN.com。如果输入 mail.THEIR-DOMAIN.com,apache 会显示 webmail.example.com,因为它是第一个虚拟主机,而 mail.THEIR-DOMAIN.com 不存在。最近,我们为 webmail.example.com 强制使用 https,并添加了此 mod_rewrite 规则:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

但现在用户无法像以前一样获得默认的 Webmail 页面。我们如何才能将所有来自 URL“mail.ANY-DOMAIN.com”的请求重定向到“https://webmail.example.com“?我尝试了以下方法,但没有效果:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (mail.*) https://webmail.example.com

提前感谢您的帮助。

答案1

尝试这个:

NameVirtualHost *:80    
<VirtualHost *:80>   
RewriteEngine On   
RewriteCond %{HTTP_HOST} ^mail. [NC]   
RewriteRule ^(.*)$ https://webmail.example.com/$1 [L,R=301]    
</VirtualHost>

相关内容