Squirm 中的负正则表达式(用于 Squid)。可能吗?

Squirm 中的负正则表达式(用于 Squid)。可能吗?

有人用 Squirm 实现了负正则表达式(或部分正则表达式)吗?
我尝试了负前瞻和 ifthenelse 正则表达式,但 Squirm 1.26 无法理解它们。

我想要做的很简单:
* 如果 URL 以“http://”开头且包含“account”,则重写/重定向到 301:https://
* 如果 URL 以“https://”开头且不包含“account”,则重写/重定向到 301:http://

到目前为止,我使用 2 行 perl 来实现这一点,但 squirm 重定向器占用的内存较少

答案1

感谢 Squirm 的所有者 Chris Foote,我利用他的技巧让它工作起来。之前我没想到 Squirm 会在模式匹配后停止重写

regexi ^(https:\/\/.*\/account.*)$ \1 account
regexi ^http:\/\/(.*\/account.*)$ 301:https://\1 account
regexi ^https:\/\/(.*)$ 301:http://\1 https

克里斯
向我解释了如何处理这种情况:

为了绕过通用的重写规则,我之前所做的就是预先放置一条与您不想重定向的内容匹配的规则,只重播原始 URL 而不进行 301 重定向。例如:

regexi (some_pattern) \1       # let through URL unwritten
regexi (http://mydomain/all-to-one-page\.html) \1 # allow \
      direct access to redirect page in the rule below.
regexi .* 301:http://mydomain/all-to-one-page.html  # all \
      other requests get redirected to a single page.

相关内容