req.hash using req.url without query string ?

Laurence Rowe l at lrowe.co.uk
Thu Apr 21 13:36:11 CEST 2011


On 21 April 2011 11:17, cosmih <cosmih at gmail.com> wrote:
> Hi,
> By default the cache key is made using req.http.host and req.url and this
> means that for the same resource requested with a different query string we
> have a different cache key, object.
> However I need that for few specific URLs (static content) to have only one
> cache object per URL and serve it no matter what query string I have.
> Something like in the below example:
> Lets suppose that I have the following URLs:
> www.example.com/a_specific_path/image.png?parameter1=value1
> www.example.com/a_specific_path/image.png?parameter2=value2
> www.example.com/a_specific_path/image.png?parameter3=value3
> :
> :
> www.example.com/a_specific_path/image.png?parameterN=valueN
> I want to use only
> /a_specific_path/image.png   +  req.http.host
> for creating/checking  the cache key and to serve this cache object no
> matter what query string "parameterN=valueN" I have to this specific URL.
> It is possible ?
> Thanks,

You can normalize the url on the way in, something like this should do
the trick:

sub vcl_recv {
    set req.url = regsub(req.url, "\?.*$", "");
}

Laurence




More information about the varnish-misc mailing list