You know how sometimes it seems like the entire world is against you? The other day was like that for me.
I wanted to add a simple url redirect for a vhost using url.redirect in lighttpd, but It seemed like no matter what I tried it just wouldn't work. The vhost configuration contained a rewrite rule that would rewrite all non static file requests to the same file. I knew that this catch-all rule would capture the request I wanted to redirect so I added the redirect rule at the top of the configuration as I would have done had this been an apache environment.
Turns out that unlike apache, lighttpd will always trigger rewrites before redirects regardless of their order in the configuration. This is another one of those undocumented quirks that makes it difficult to move from apache to lighttpd. To me this behavior is quite strange. Why waste cpu-cycles rewriting an url if you are going to redirect the visitor away from your site?
Once I knew about the rewrite quirk the solution was quite simple, just add another rewrite rule that does nothing if the request url matches your redirect pattern. It's a bit clumsy but it works.
ex:
url.redirect = ("^/foobar/(.*)$" => "http://somewhereelse.com/$1")
url.rewrite = (
"^/foobar/(.*)$" => "$0",
"^/(?!(_css|_js|_img))" => "/mvc.php"
)
This was even more annoying than when I spent a few hours trying to get each of my vhosts to write to their own error log. It doesn't work, lighttpd only supports one error log. gaAH!! ;)
Works for me.
$HTTP["host"] =~ "domain1\.com$"{
accesslog.filename="/www/logs/domain1-access.txt"
server.document-root="/www/domain1"
server.errorlog="/www/logs/domain1-error.txt"
}
$HTTP["host"] =~ "domain2\.com$"{
accesslog.filename="/www/logs/domain2-access.txt"
server.document-root="/www/domain2"
server.errorlog="/www/logs/domain2-error.txt"
}
Thank you that's what I wanted to do :)