lighttpd,mod_rewrite和web.py意外行为

时间:2010-12-26 07:41:09

标签: python mod-rewrite lighttpd web.py

我已将lighttpd配置为使用web.py.现在,我想通过我的web.py脚本以 mysite.com/scripts / * 的形式处理所有请求。这就是lighttpd.conf的相关部分:

fastcgi.server = ("/code.py" =>
(("socket" => "/var/tmp/lighttpd/fastcgi.socket",
  "bin-path" => "/var/www/code.py",
  "max-procs" => 1,
  "check-local" => "disable",
))
)

url.rewrite-once = (
  "^/scripts/(.*)$" => "/code.py/$1",
)

我设置了一个简单的code.py,用于打印URL中显示的内容。这是代码:

urls = (
    '(.*)', 'hello')

app = web.application(urls, globals(),True)

class hello:
    def GET(self, x):
        return "I have received: " + web.websafe(x)

当我输入 mysite.com/code.py/test 时,我看到“我收到了:/ test”,这是正确的,但是当我输入< strong> mysite.com/scripts/test ,我看到“我收到了:/ scripts / test”

我希望重写规则能匹配/ scripts /之后的内容并将URL重写为/code.py/test,为什么它还传递/ scripts部分?

1 个答案:

答案 0 :(得分:0)

"/scripts/test""/test"(.*)完全匹配。如果您只想匹配两个网址的"test"部分,可以写下这样的内容。

urls = (
  r'(.*)/(.*)', 'hello',
)

app = web.application(urls, globals(), True)

class hello(object):
  def GET(self, x, y):
    return 'i have received ' + web.net.websafe(y)