在不使用mod_rewrite的情况下,将所有子域redirect到https的最佳方法是什么?

我目前正在使用mod_rewriteredirect到https的所有子域名,但多个来源已经build议

使用mod_rewrite来做这不是推荐的行为。 请参阅RedirectSSL

apache文档build议redirect和RedirectMatch:

RewriteRule的一个常见用途是redirect整个类的URL。 例如,/ one目录中的所有URL都必须redirect到http://one.example.com/ ,或者所有http请求都必须redirect到https。

这些情况最好通过Redirect指令处理。 请记住,redirect保留了path信息。 也就是说,redirect一个URL /一个也会redirect所有的URL,比如/one/two.html和/one/three/four.html。

不幸的是,这些文档(以及其他所有我发现的)都只考虑匹配一个域,而不是所有的子域。 RedirectMatch似乎是这样一个相对简单的任务的好候选人,但我似乎无法得到“http”匹配,如我所料:

RedirectMatch permanent "^http://(.*)$" "https://$1" 

我的猜测,为什么这是行不通的,因为redirectMatch正在寻找一个path,而不是一个URI,但在这一点上,我卡住了。 是否有可能完成所有子域的redirect到https没有mod_rewrite,或者是最好的方法?

通常,对于不同的VHosts的子域,我将下面的行添加到每个域中。

 Redirect permanent / https://bar.example.com/ 

我通常只是为每个子域添加其中的一个。 如果你有很多的子域,这个方法可能不是很有伸缩性,但是很简单,并且完成了工作。