Varnish redirection

Erik Weber twiztar at gmail.com
Fri Jun 24 23:04:55 CEST 2011


On Fri, Jun 24, 2011 at 10:00 PM, Flatcircle <flatcircle at hotmail.com> wrote:
> Hello,
>
> I saw that it is possible to redirect domains with a 'dirty' hack.
> (http://www.varnish-cache.org/trac/wiki/VCLExampleRedirectInVCL)
> This works well.
>
> However, is it also possible to redirect subdirectories on a domain?
>
> For example:
>
> http://www.example.com/somesubdirectory
>
> should redirect to
>
> http://www.adifferentsite.com


sub vcl_recv {
if (req.url ~ "^/somesubdirectory/?$") {
 error 750 "http://www.adifferentsite.com";
}
}

sub vcl_error {
if (obj.status == 750) {
 set obj.http.Location = obj.response;
 set obj.status = 302;
 return (deliver);
}
}

-- 
Erik




More information about the varnish-misc mailing list