How to enable http auth in lighttpd for all directories except one

http-basic-authenticationlighttpd

I am trying to authenticate access to everything in webroot (/) except anything that resides in a particular directory (/directory/) and I've tried both of these options to no avail:

$HTTP["url"] =~ "^(?!(/directory))" {
    auth.require = ( "" =>
            (
            "method" => "basic",
            "realm" => "auth to this area",
            "require" => "user=username"
            )
    )
}

$HTTP["url"] != "/directory" {
    auth.require = ( "" =>
            (
            "method" => "basic",
            "realm" => "auth to this area",
            "require" => "user=username"
            )
    )
}

Best Answer

Try this:

$HTTP["url"] !~ "^/directory" {
    auth.require = ( "" =>
            (
            "method" => "basic",
            "realm" => "auth to this area",
            "require" => "user=username"
            )
    )
}