I'm working on migrating a site to another platform. We have a Python script to handle the import and we're considering using Varnish for speed. I want to make sure all existing URLs remain functional (in the form of 301 redirects) and I'm considering doing this directly in Varnish. We're talking about 3k+ URLs and we won't be able to catch this into a couple of regular expressions.

Ideally I would keep the list of redirects in a separate file, json, csv or xml but from a bit of research it seems there's no straightforward way to do this except for generating a huge .vcl file with elseifs with the import script. Is there a nicer way to do mass 301 redirects in Varnish?

up vote 1 down vote accepted

Check this solution: https://www.varnish-cache.org/vmod/database-driven-rewrites and also this one: https://github.com/brandonwamboldt/libvmod-redis

This should do the trick for you.

  • Welcome to Server Fault! Your answer suggests a workable solution to the question is available via another website. The Stack Exchange family of Q&A websites generally frowns on this type of answer because other websites may move, get deleted, or changed. Please read How do I write a good answer? and consider revising your answer to include the steps required to resolve the issue. – Paul Feb 20 '15 at 17:06
  • 1
    Just to add to @Paul his comment. You don't need to entirely remove the links or place the entire explanation in your answer. But we do request all answers to have at least the basic reasoning for the answer or the headlines of the steps in the answer linked to be present. – Reaces Feb 20 '15 at 17:07


There is no way to link Varnish to any kind of datastore like this. However, Varnish can cache your 301 responses, so you could have a simple backend that returns the 301 and then set a very long TTL on that in your VCL. It should be trivial to write a PHP / python / etc script that reads the data file and sends the 301.

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.