lighttpd、mod_rewrite 和 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”,这是正确的,但是当我输入mysite.com/scripts/test,我看到“我已收到:/scripts/test”。
我期望重写规则与 /scripts/ 之后的内容相匹配,并将 URL 重写为 /code.py/test,为什么它也传递了 /scripts 部分?
I have configured lighttpd to work with web.py. Now I want to process all requests in the form mysite.com/scripts/* via my web.py script. This is how the related part of lighttpd.conf looks like:
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",
)
I set up a simple code.py that prints what appears in the URL. This is the code:
urls = (
'(.*)', 'hello')
app = web.application(urls, globals(),True)
class hello:
def GET(self, x):
return "I have received: " + web.websafe(x)
When I enter mysite.com/code.py/test, I see "I have received: /test", which is right, but when I enter mysite.com/scripts/test, I see "I have received: /scripts/test".
I was expecting the rewrite rule to match what comes after /scripts/ and rewrite the URL as /code.py/test, why is it also passing the /scripts part?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
"/scripts/test"
和"/test"
与(.*)
整体匹配。如果您只想匹配两个 URL 的"test"
部分,您可以编写如下内容。"/scripts/test"
and"/test"
are matched by(.*)
as whole. If you want to match only the"test"
part of both URLs, you may write something like this.