重定向规则以匹配某些关键字但不匹配其他关键字

Redirect Rule to match certain keywords but not others

我正在尝试编写一个 RedirectMatchapache)来匹配除一个以外的一些关键字。

...
RewriteEngine  on
RedirectMatch   ^/(banners|documents|images|static)/(.*)$ http://sb.amazonaws.com//
RewriteRule     ^(.*)/(vrf[0-9]+)/(.*).(js|css)$  /. [PT]

我想出了这个 RedirectMatch 规则,将所有包含横幅、文档等的 url 重定向到 aws 域。

现在,我想阻止包含 temp 的 url 转到 aws 域。为此,我添加了 !temp

RedirectMatch   ^/(!temp|banners|documents|images|static)/(.*)$ http://sb.amazonaws.com//

这不允许像 mysite.com/temp/a.jpg 这样的 url 访问 AWS(但抱怨无限循环) 但不会阻止 mysite.com/images/temp/a.jpg 被重定向。此规则的正确正则表达式应该是什么?

[编辑]

[EDIT2] 这让我接近了我要找的东西

RewriteEngine  on
RewriteRule ^(images/groups/temp)/(.*)$ / [PT]
RewriteRule ^(banners|documents|images|static)/(.*)$ http://sb.amazonaws.com//
RewriteRule ^(.*)/(vrf[0-9]+)/(.*).(js|css)$  /. [PT]

不要将 RedirectMatchRewriteRule 混用。使用 RewriteCond 添加例外:

RewriteEngine  on

RewriteCond %{REQUEST_URI} !^/images/groups/temp/ [NC]
RewriteRule ^(banners|documents|images|static)/(.*)$ http://sb.amazonaws.com// [L,NC,R]

RewriteRule ^(.*)/(vrf[0-9]+)/(.*).(js|css)$  /. [PT]