繁体   English   中英

如何在没有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情况下完成此操作(正如我在其他问题中发现的那样)?

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

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

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

但我不能写一个正则表达式来处理其他三个。 我在这个答案中发现我可以使用负面的外观,但像/(?!services).*这样的正则表达式只会匹配4(至少根据Regex Tester

编辑

我已经指定这可以在没有mod_rewrite情况下完成。

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

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

(?!services)是一个负向前瞻,除了以/services开头的URL之外的任何URL

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM