gpt4 book ai didi

python - lighttpd、mod_rewrite 和 web.py 意外行为

转载 作者:太空宇宙 更新时间:2023-11-04 06:38:48 25 4
gpt4 key购买 nike

我已经将 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 部分?

最佳答案

"/scripts/test""/test"(.*) 整体匹配。如果你只想匹配两个 URL 的 "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)

关于python - lighttpd、mod_rewrite 和 web.py 意外行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4533109/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com