【问题标题】:Varnish 4 rewrite URL transparentlyVarnish 4 透明地重写 URL
【发布时间】:2016-08-18 16:27:42
【问题描述】:

我正在管理一个网站,该网站目前正在运行一个非常标准的 varnish/apache 设置。客户端需要添加一个从路径/查询字符串透明地提供服务的新域,以便创建其站点的轻量级版本。例如:

用户访问指向与 example.com 相同的服务器的 mobile.example.com

Varnish 将 mobile.example.com 请求重写为 example.com/mobile?theme=mobile

用户收到由 apache 从 example.com/mobile?theme=mobile 提供的页面,但仍停留在 mobile.example.com

我们需要点击路径并在此处添加查询字符串,并维护用户输入的任何路径,即:mobile.example.com/test 应该在 example.com/mobile/test 处提供内容?主题=移动

关于使用 Varnish 4 执行此操作的任何提示?有可能吗?

【问题讨论】:

    标签: apache .htaccess varnish varnish-vcl varnish-4


    【解决方案1】:

    搞定了!

    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");
    } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-06
      • 2019-03-05
      • 2017-11-22
      • 2012-12-09
      • 1970-01-01
      • 2014-01-10
      相关资源
      最近更新 更多