Varnish VCL: Case Insensitive Regex

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, April 27, 2015

Follow me on Twitter as @mattiasgeniar

By default, a regex match in Varnish happens case sensitive. If you want to use a case insensitive check, you can use the (?i) flag.

This is a normal, case sensitive regex check:

if (req.http.host ~ "^domain.(be|nl|com)$") {
  ...
}

To make the same check case insensitive, add the (?i) modifier at the beginning.

if (req.http.host ~ "(?i)^domain.(be|nl|com)$") {
  ...
}

Odd as it may be, some people type in their domain names with caps, and the browser does not convert those to lowercase on submit. Though in practice, every Host-header is treated as a lowercase value in all webserver configs.



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.