views:

70

answers:

1

Hello, 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):

http://myapplication.com/products/?startindex=1&endindex=10

Desired URL:

http://myapplication.com/products/?paginate=1:10

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:

http://myapplication.com/search/?query=something

to:

http://myapplication.com/search/?q=something

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

Thanks

+1  A: 

Apparently you can. The answer is that regsub is your friend.

For example:

if (req.url ~ "(.*)(id=)") {
        set req.url = regsub(req.url, "(feeds/[a-zA-Z]*/)(.*)([\?|&])(id=)([a-zA-Z0-9]*)(.*)", "\1\2\3byGuid=\5\6");
}

This will convert and incoming "id" parameter into a "byGuid" parameter on the backend. t also does a bunch of stuff with the rest of the URL string but the basics are there. SO if anyone wants to do something similar this is a good starting point.

Pinguthepenguin