我已将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部分?
答案 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)