2

I am looking after a website that is currently running a pretty standard varnish/apache set up. The client needs to add a new domain that transparently serves from a path/query string in order to create a lightweight version of their site. For example:

The user visits mobile.example.com which points to the same server as example.com

Varnish rewrites the mobile.example.com request to example.com/mobile?theme=mobile

User receives the page served from example.com/mobile?theme=mobile by apache, but stays on mobile.example.com

We need to hit both a path and add the query string here, as well as maintain any path the user has entered, i.e: mobile.example.com/test should serve the content at example.com/mobile/test?theme=mobile

Any tips for doing this with Varnish 4? Is it possible?

Felix
  • 159
  • 1
  • 9

1 Answers1

9

Got it working!

if (req.http.host ~ "^mobile\.example\.com") {
  set req.http.host = "example.com";
  set req.url = regsub(req.url, "^/", "/mobile/");
  set req.url = regsub(req.url, "$", "?theme=mobile");
} 
Felix
  • 159
  • 1
  • 9