我为一个站点启用了HTTPS,所有对HTTP的请求现在都应该redirect到HTTPS, 除了一个目录的内容,例如/downloads 。
我改变了我的VirtualHostconfiguration为HTTP,并添加了RedirectMatch设置:
<VirtualHost *:80> ServerName example.com RedirectMatch 302 ^/(?!download/).*$ https://example.com$1 ProxyPreserveHost On ProxyRequests Off ProxyPass / http://10.0.0.11:3000/ ProxyPassReverse / http://10.0.0.11:3000/ </VirtualHost> # configuration for HTTPS down here, working fine
我的期望:诸如http://example.com/faq请求将被redirect到HTTPS版本,并且所有请求(如http://example.com/download/file.zip仍然是HTTP。
但显然, Proxy*指令具有更高的优先级,根本不会发生redirect。
我将如何正确构build我的configuration,以便我可以使用RedirectMatch ,并在不匹配的情况下使用Proxy*设置?
好吧,没有看到树木的森林。 解决scheme如下:
<VirtualHost *:80> ServerName example.com RedirectMatch 302 ^/(?!download/).*$ https://example.com$1 ProxyPreserveHost On ProxyRequests Off ProxyPass /download/ http://10.0.0.11:3000/download/ ProxyPassReverse /download/ http://10.0.0.11:3000/download/ </VirtualHost>
所以,Proxy指令只能用于RedirectMatch排除的路由。