Is it possible to simulate this rewrite in vcl?
Nils Goroll
slink at schokola.de
Thu Mar 25 14:36:06 CET 2010
Regarding this old thread:
>> I've had to put an instance of apache behind varnish as a redirector as I
>> can't think of a way of making varnish do it. Can this apache rewrite be
>> done in vcl?
>>
>> RewriteRule ^/(.*)/home/(.*)$ http://$1_host.example.com/$2 [P]
>
> Not right of the bat.
>
> Provided you add backend instances for all the servers serving
> these domains it is possible, but you need to do the $1 part as
> a if/elseif/elseif/elseif/.../else to set the req.backend.
Something I have just published recently might help:
http://varnish-cache.org/ticket/666
I haven't tested Rob's specific case, but something like the following *SHOULD*
work (don't pick on syntax errors please):
if (req.url ~ "(.*)/home/(.*)") {
set req.url = pmatch.2;
if (pmatch.1 == "server1") {
set req.backend = "server1";
} elseif (pmatch.1 == "server2") {
...
} else {
error 543 "wrong server"
}
}
Please report bugs of the pmatch feature if you find any.
Cheers, Nils
More information about the varnish-misc
mailing list