I’m using lighttpd 1.4.28
Here is my redirect rule :
$HTTP["host"] =~ "^([^.]+\.[^.]+)$" {
url.redirect = ( "^/(.*)" => "http://www.%0/$1" )
}
It’s supposed to redirect anydomain.anytld to http://www.anydomain.anytld and it works like a charm like I’ve written it here (of course, using %1 also works, since it refers to the parentheses.)
Yet, I’m baffled as to why it only works with the pair of parentheses you can see in the trigger regex.
%0 is supposed to catch the whole result, isn’t it ? It doesn’t even refer to a pair of parenthese, unlike %1, %2, etc. But if I remove those parentheses, like this :
$HTTP["host"] =~ "^[^.]+\.[^.]+$" {
url.redirect = ( "^/(.*)" => "http://www.%0/$1" )
}
I get this error when trying to restart lighttpd :
unreachable else condition 2012-10-17 11:34:10: (configfile.c.918)
source: /etc/lighttpd/lighttpd.conf line: 173 pos: 14 parser failed
somehow near here: (EOL)
Thanks !
It’s because
%0matches the entire substring or the first expression, which, by definition is the enclosing()set. This would allow you to use a more complicated regex with nested (ie((()))) parenthesis, and pulling the entirety of it. From what I can understand, that is the construct of Lighttpd’s regex parser.http://redmine.lighttpd.net/projects/1/wiki/Docs_ModRewrite