重定向除一个文件夹和索引文件之外的所有 Lighttpd 流量

Redirect all Lighttpd traffic apart from one folder and index file

我希望应用以下规则

$HTTP["host"] =~ "^www\.example\.com$" {
        url.redirect = ( "^/(.*)" => "http://newlocation.example.com/" )
}

但是如果用户请求:

请求应该正常服务

www.example.com/ -> 正常投放

www.example.com/tools/style.css -> 正常投放

www.example.com/example.html -> http://newlocation.example.com/example.html

你可以匹配所有你想要正常服务的文件,然后使用else重定向其余的。像这样:

$HTTP["host"] =~ "^www\.example\.com$" {
    $HTTP["url"] =~ "^/(index\.html|tools/|)$" {
        server.document-root = "/path/to/files"
    } else {
        url.redirect = ( "^/(.*)" => "http://newlocation.example.com/" )
    }
}