lighttpd身份验证和重写相同的URL无法正常工作

时间:2013-01-10 07:07:46

标签: mod-rewrite lighttpd mod-auth

我似乎无法在同一个网址上同时进行身份验证和重写。如果我禁用一个,另一个工作。这在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"
   )
}

2 个答案:

答案 0 :(得分: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"
        )
      )
    }
  }
}

答案 1 :(得分:1)

我找到了解决方法。似乎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"
      )
    )
}

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