4

I want to manipulate the client url "www.example.com/download.." to "one.other.com/download... But I want that the url on the client maintain the first "www.example.com/download"

Is there any way with Varnish 3 to do this??

enb081
  • 3,831
  • 11
  • 43
  • 66
user2072574
  • 41
  • 1
  • 2

1 Answers1

4

Yes, you can easily do it using the regsub() function in VCL in vcl_recv.

For instance:

if (req.http.host ~ "^(www\.)?example\.com" && req.url~ "^/download/") {
  set req.http.host = "one.other.com";
  set req.url = regsub(req.url, "^/download/", "/");
} 

This examples rewrites access to http://www.example.com/download/example.jpg to http://one.other.com/example.jpg. Of course, it is not visible to the user.

enb081
  • 3,831
  • 11
  • 43
  • 66
  • This results in a 302 being returned to the client for me with the altered URL. I'm trying to change the request that gets sent to my backend. – ironchicken Feb 12 '19 at 17:20