lighttpd、mod_rewrite 和 web.py 意外行为

发布于 2024-10-09 08:40:24 字数 908 浏览 6 评论 0原文

我已将 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魄砕の薆 2024-10-16 08:40:24

"/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)

"/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.

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)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文