Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a relatively simple (I think) use-case but I can't find any examples where someone has done this. We are using Varnish as a cache and reverse proxy in front of two different applications and would like to make things a bit more unified across both as they both do similar things. I was hoping Varnish could help rewrite the URLs as shown below.

Original application URL for pagination (get first 10 items):

// Desired URL:

// This is just one example (the most complex because it combines two parameters), but in all cases the input values for the parameters stay the same, it is just that the parameter names will change.

Another example would be:

// to:

// Does anyone have any experience with varnish and how this could be done?


share|improve this question

If you want to internally rewrite the URLs, put the following (untested) in vcl_recv:

set req.url = regsub(

If you want to 301 requests from one URL style to the other then it's a little more complicated, but here's a rough start on how you might do it:


set req.http.X-Redirect-URL = regsub(
error 700 req.http.X-Redirect-URL;


if (obj.status == 700) {
    set obj.http.Location = obj.response;
    set obj.status = 301;
    set obj.response = "Moved Permanently";

Obviously, if you have other parameters you're going to have to jump through a few more hoops to ensure that they get correctly passed through.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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