我正在尝试创建一个反向代理,它匹配除 Apache 2.2 中的一个之外的每个 URL。它适用于 Apache 2.4 (Centos 7),但不适用于 Apache 2.2 (Centos 6.6) ...
# Do not modify this
<LocationMatch "^/my-website-2">
ProxyPass http://X.X.X.X:PORT/my-website-2
ProxyPassReverse http://X.X.X.X:PORT/my-website-2
(...)
</LocationMatch>
# Match every URL except the one finishing with /redirect
<LocationMatch "^/my-website(?!/redirect)">
ProxyPass http://X.X.X.X:PORT/my-website
ProxyPassReverse http://X.X.X.X:PORT/my-website
AuthType XXX
RequestHeader set XXX YYY
(...)
</LocationMatch>
# Do anothers directives with this URL only, finishing with /redirect
<Location "/my-website/redirect">
AuthType XXX
(...)
</Location>
Run Code Online (Sandbox Code Playgroud)
当我输入https://my-server.com/my-website因为正则表达式不匹配 ^/my-website时,我的服务器正在寻找 /var/www/html/my-website(不存在的)(?!/重定向)
我知道 Apache 2.2 不能理解每个负面 PCRE 正则表达式,但似乎存在一些技巧......请参阅: