我有一个apache 2.4反向代理服务器设置,它根据请求URL从两个不同的后端Web服务器之一获取内容。
默认情况下,所有http请求都会重定向到https。
但是,我需要通过允许两个不同的URL保持为http来为默认设置提供两个例外。
请注意,由于域名发布限制,反向代理域是example.com,其中一个后端服务器是example.org
我对反向代理的http(非安全)apache实例有以下配置:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/this [OR]
RewriteCond %{REQUEST_URI} !^/that
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule ^/that$ /that/ [R=301,L]
<Location /that/>
ProxyPass http://example.org/that/
ProxyPassReverse http://example.org/that/
</Location>
RewriteRule ^/this$ /this/ [R=301,L]
<Location /this/>
ProxyPass http://example.org/
ProxyPassReverse http://example.org/
</Location>
如果我浏览http://example.com,我会按预期重定向到https://example.com。
如果我尝试浏览http://example.com/this或http://example.com/that,我会收到以下错误:
The page isn’t redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
This problem can sometimes be caused by disabling or refusing to accept cookies.
如果我只是单独添加这个或那个,它没有任何问题,所以当我添加[OR]标志时,似乎会导致错误。
例如,这有效:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/this
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule ^/this$ /this/ [R=301,L]
<Location /this/>
ProxyPass http://example.org/
ProxyPassReverse http://example.org/
</Location>