change ttl based on request url

Viktor Villafuerte viktor.villafuerte at
Tue Nov 3 08:07:16 CET 2015

Hi Ryan,

you're mixing req.url with

Also be aware of changes between Varnish 3 and 4. You didn't specified
which version you're using so I won't go into details. Those can be
found here

On Mon 02 Nov 2015 22:22:10, Ryan Morgan wrote:
> I have multiple subdomains pointing to one varnish instance. I read in the documentation that PCRE regex should be used. I believe the regex I have below should return true when the request url is “ <>” and the 15s ttl should be set. I’ve tried just (req.url ~ “ <>”) as well because I read that it should match if any part of the request url. Help is appreciated! Thanks!
> -Ryan
> # Cache for a longer time if the URL isn't used
> sub vcl_fetch {
>   if (req.url ~ "^[(http:\/\/)|(https:\/\/)]*internal\.my\.com.*"){

what you're matching here is and so the statement never
returns true because it never matches

Also I don't like the way the regex looks. I have not tested this so
quite possibly it works but it's bit ugly. I'm sure simpler and cleaner
regex could/should be found.


>     set beresp.ttl = 15 s;
>   } else {
>     set beresp.ttl = 300 s;
>   }
> }

> _______________________________________________
> varnish-misc mailing list
> varnish-misc at


Viktor Villafuerte
Optus Internet Engineering
t: +61 2 80825265

More information about the varnish-misc mailing list