Changing req.hash

Martin Goldman me at
Tue Jun 1 14:07:26 CEST 2010

Hi folks,

We're adding a mobile version of our site. We don't want to redirect mobile
users to a different URL, we want to just present the mobile site to
visitors who access our site with a mobile-like useragent. So I got the idea
from this site ( to change req.hash for
mobile requests so that they'll get cached separately using logic like this:

sub vcl_hash {
  /* Have a separate object cache for mobile site based on User-Agent */
  if ( == "" && req.http.User-Agent ~
"(iPhone|iPod)") {
    set req.hash += "mobile";

This basically works as expected, but I'm having one issue. We
programmatically purges pages from Varnish when they're updated. Obviously
to do so, we need to know the hash of the page. The hash syntax we've always
used, which works fine for the non-mobile requests, is:


But I'm not totally clear on how appending "mobile" to the hash changes the
syntax. I remember reading once that custom VCL runs *before* the default
VCL, so I thought the hash would be something like this:


However, purging that doesn't work. Any ideas?

Apologies if the answer to this is out there somewhere, I just haven't had
any luck finding it.

Thanks and regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the varnish-misc mailing list