The Importance of reading the regexp properly No rating results yet

I did mention that my varnish 4.0 configuration was pretty much out of the box here.

Well, there are some things that can come back to bite you when you copy’n’paste stuff that you find with google.

One client was very patient with me today whilst some serious head scratching happened today whilst we tried to work out why we had broken the shopping cart on one vhost on the same server, but not another, with identical versions of opencart running in the background.  I was all ready to give up and put in a “don’t cache this site/VHOST” entry into the VCL, when something caught my eye.

# Cache the following files extensions
if (req.url ~ "\.(css|js|png|gif|jp(e)?g|swf|ico)") { unset req.http.cookie; }

Read that regexp carefully.  Yes it doesn’t do quite what you expect it to.

if (req.url ~ "\.(css|js|png|gif|jp(e)?g|swf|ico)$") { unset req.http.cookie; }


Works much more consistently, and more to the point as intended.

Pay attention to the detail, and remember there is always a reason for strange behaviour, the code only follows the rules we give it.