正则表达式帮助. Lighttpd重写规则 [英] Regex help. Lighttpd rewrite rule

查看:126
本文介绍了正则表达式帮助. Lighttpd重写规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对正则表达式不是很熟悉,但是要求我修改lighttpd重写规则.

I am not very familiar with Regular expression, but I am asked to modify a lighttpd rewrite rule.

url.rewrite = (
    "^/(.+)/?$" => "/index.php/$1"
)

我想从上面的贪婪模式中排除路径,以使它不会退回到 index.php .

I want to exclude a path from the above greedy pattern, so that it won't fall back to index.php.

很简单:匹配除统计"之外的任何内容.但是我只是无法在正则表达式中做到这一点.

In words, it is simple: Match anything other than "statistics". But I just couldn't get it right in regex.

例如:

  • http://www.foo.com/anything/index.php/anything
  • http://www.foo.com/statistics/statistics/index.php
  • http://www.foo.com/anything/index.php/anything
  • http://www.foo.com/statistics/statistics/index.php

您能告诉我实现该目标的提示吗?

Would you please show me a hint to achieve that?

谢谢!

推荐答案

您可能想使用否定的前瞻.像

You probably want to use a negative lookahead. Something like

"^/(?!statistics)(.+)/?$" => "/index.php/$1"

然后您需要一条附加的统计规则

And then you'll need an additional rule for statistics

这篇关于正则表达式帮助. Lighttpd重写规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆