[英]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和RedirectMatch指令处理的。
所以我可以处理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.