如何在没有 mod_rewrite 的情况下重定向除一个路径及其所有子路径之外的所有 URL?

How to redirect all URLs except one path and all its subpaths without mod_rewrite?

我在 Tomcat 7 之前安装了 Apache 2.4(尽管我认为前者在这里很重要)。 我需要将域上的所有请求重定向到 HTTPS 端口,而不是那些转到特定文件夹的请求:

(1) http://www.example.com/ -> https://www.example.com/
(2) http://www.example.com/products -> https://www.example.com/products
(3) http://www.example.com/... -> https://www.example.com/...

(4) http://www.example.com/services should pass straight 
(5) http://www.example.com/services/main should pass straight
(6) http://www.example.com/services/main/list?params should pass straight

如何在不使用 mod_rewrite 的情况下完成此操作(正如我在其他问题中发现的那样)?

我在文档中看到重定向是使用 Redirect and RedirectMatch 指令处理的。

所以我可以处理 1,2,3:

<VirtualHost *:80>
    ...
    ServerName www.example.com
    Redirect / https://www.example.com
</VirtualHost>

但我无法编写正则表达式来处理其他三个。我在 this answer that I can use negative lookarounds, but a regex like /(?!services).* will only match 4 (at least according to Regex Tester on

中找到

编辑

我已指定无需 mod_rewrite 即可完成此操作。

在此处使用基于正则表达式的重定向规则:

<VirtualHost *:80>
    ...
    ServerName www.example.com
    RedirectMatch 301 ^/((?!services).*)$ https://www.example.com/
</VirtualHost>

(?!services) 是一个否定前瞻,它将 URL 除了以 /services

开头的那些