Varnish proxy - Modify routes and urls of Slim 4 application

Hi,

I have a project where Varnish is used in front of a Slim 4 project. Due to some project specialities, the original url should be hidden and the incoming request is rewritten to some other headers.

Example

  • Original call to demo.xyz is coming to Varnish
  • Varnish is transforming the request to http://slimapp.dev/url/demo.xyz
  • The original host is saved in the header with X-Orig-Host: demo.xyz

The Slim App needs to detect if it is a Varnish request (I already got that) and needs to transform the routes.

So when creating a route with url_for (Twig-View package) the urls should be generated like that:

  • Route w/o Varnish: http://slimapp.dev/url/demo.xyz/article/123
  • Route w/ Varnish: http://demo.xyz/article/123

Ideas:

  1. Modify the original UriInterface object but I have no idea how.
  2. Write a TwigExtension for Twig-View to modify the methods for url_for and so on.

Any idea what to do?

Thanks in advance!

Hmm, no one? If anything is unclear, let me know.

So it boils down to if it is a request with Varnish it needs to assemble the routes urls from X-Orig-Host instead of HTTP_HOST. So I think I am going for overriding the UriFactory where the Uri is constructed.

Any opinions on that?