0

我似乎无法在同一个 url 上同时获得身份验证和重写。如果我禁用一个,另一个工作。这在lighttpd中可行吗?

$HTTP["host"] =~ "www\.example\.com$" {
   auth.require = (
     "/prettyurl" =>
     (
      "method" => "basic",
      "realm" => "Password reqired",
      "require" => "valid-user"
     )
   )
   url.rewrite = (
         "/prettyurl" => "/index.php?foo=bar&goo=car"
   )
}
4

2 回答 2

2

我通常封装auth.require在一个$HTTP["url"]. 像这样的东西:

$HTTP["host"] =~ "www\.example\.com$" {
  url.rewrite = (
    "/prettyurl" => "/index.php?foo=bar&goo=car"
  )

  $HTTP["url"] == "/index.php" {
    $HTTP["querystring"] == "foo=bar&goo=car" {
      auth.require = ( "" =>
        (
          "method"  => "basic",
          "realm"   => "Password reqired",
          "require" => "valid-user"
        )
      )
    }
  }
}
于 2013-01-10T08:22:53.083 回答
1

我找到了解决方案。似乎在 url 的查询字符串部分既不匹配auth.require也不匹配。$HTTP["url"]

首先做一个符号链接

ln -s index.php index_auth.php

然后在 lighttpd conf 中:

$HTTP["host"] =~ "www\.example\.com" {
    url.rewrite = (
       "/prettyurl-auth" => "/index_auth.php?foo=bar",
       "/prettyurl-noauth" => "/index.php?goo=car"
    )
    auth.require = ( "/index_auth.php" =>
      (
        "method"  => "basic",
        "realm"   => "Password reqired",
        "require" => "valid-user"
      )
    )
}

如果有更好的方法,请告诉我!

于 2013-01-10T19:53:34.290 回答