Rewrite URL before passing to proxy Lighttpd

configurationlighttpdmod-proxyrewriteurl

I'm trying to setup a reverse proxy in lighttpd, such that all requests (and only those requests) under /mobile/video is redirected to the / directory of a secondary web server. This is pretty easy in apache, but I can't for the life of me figure out how to do so in lighttpd.

$HTTP["url"] =~ "^/wsmobile/video/" {
       url.rewrite-once = ( "^/wsmobile/video/(.+)" => "/$1" )
       proxy.server = ( "" => ( ( "host" =>  "210.200.144.26", "port" => 9091 ) ) )
}

I've tried using the http["url"] directive, but lighttpd simply ignore those requests and continue to pass the full url to the secondary server, which of course chokes and throws 404s. However, if I do a global rewrite then everything gets forwarded to the secondary server, which is also not what I want.

How do I go about this task?

Best Answer

url rewrites won't work in $HTTP["url"]. However, you should be able to rewrite it globally in this manner:

url.rewrite-once = ( "^/wsmobile/video/(.*)" => "/test/" )

and then catch it with:

$HTTP["url"] =~ "^/test/" {

   # do proxy here

}

UPDATE:

Please see here: Lighttpd bug #164. Specifically, proxy-core.rewrite-request should be what you're looking for.

Related Topic