2

我已将 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时,我看到"I have received: /test",这是正确的,但是当我输入mysite.com/scripts/test时,我看到"I have received: /scripts/测试”

我期待重写规则匹配 /scripts/ 之后的内容并将 URL 重写为 /code.py/test,为什么它也通过 /scripts 部分?

4

1 回答 1

0

"/scripts/test"并作为整体"/test"匹配。(.*)如果你只想匹配"test"两个 URL 的一部分,你可以这样写。

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)
于 2011-01-25T18:48:29.580 回答