Keep URL after rewriting

Rangel, Raul Raul.Rangel at disney.com
Wed May 8 17:57:58 CEST 2013


So you said you set the Site-URL to www.example.com/corporate which I'm assuming makes urls like http://www.example.com/corporate/foo.php. You also said that the DocumentRoot is /. So by removing the corporate you end up with //foo.php. So you are expecting to find foo.php in the DocumentRoot. It might be the double slash that is breaking it. But I think apache will handle that correctly. Change your regsub to replace /corporate and see if that helps. Otherwise use varnishlog to look at your logs.

Raul

-----Original Message-----
From: Hauke [mailto:mailman at haukebruno.de] 
Sent: Wednesday, May 08, 2013 2:43 AM
To: Rangel, Raul; 'varnish-misc at varnish-cache.org'
Subject: Re: Keep URL after rewriting

Hi Raul,

thanks for your advices.

for wordpress I configured the Site-URL to www.example.com/corporate. That will fix my hyperlinks.

But now I have the following problem:

As shown in the config

if (req.http.host ~ "example.com" && req.url ~ "^/corporate") {
    set req.http.host = "corporate-stag.example.local";
    set req.url = regsub(req.url, "corporate", "");
  }

I remove the _corporate_ part in req.url. That's because the webapp lies directly under the DocumentRoot of _corporate-stag.example.local_. If I click some hyperlink in the webapp like _http://www.example.com/corporate/foo.php_
this does not work because of removing the _corporate_ from the req.url.

Is there any other option for my case except of moving the whole webapp from DocumentRoot to DocumentRoot/corporate and don't delete the _corporate_ part in req.url? I tried this and this will work, but it's a little bit messy at all.

Thanks,


--
Best regards,
Hauke
On Tuesday, May 07, 2013 07:12:49 AM Rangel, Raul wrote:
> I'm going to make the assumption that your webapp is writing absolute urls.
> I'm also going to make the assumption that it is using the Host header 
> to write those urls. This is why your gusts never navigate back to the 
> same domain. I see two potential options.
> 
> 1) Configure your webapp not to write full urls.
> 2) Some web frameworks support the X-Forwarded-Host header. So you 
> could set that header before you do any manipulations to it. i.e) set 
> req.http.X-Forwarded-Host = req.http.host;
> 
> Raul
> 
> -----Original Message-----
> From: varnish-misc-bounces at varnish-cache.org
> [mailto:varnish-misc-bounces at varnish-cache.org] On Behalf Of Hauke Sent:
> Tuesday, May 07, 2013 6:25 AM
> To: varnish-misc at varnish-cache.org
> Subject: Keep URL after rewriting
> 
> Hi there,
> 
> i think I've got a fallacy at the moment.
> 
> After rewriting my URLs with Varnish I want to keep the origin URL 
> given by a client.
> 
> We want to use our domain with some followed seperators, e.g.
> www.example.com/corporate should point to a specific webapp, 
> www.example.com/service should point to another webapp and so on.
> 
> The backend servers listen to some internal names like corporate- 
> stag.example.local.
> 
> Here is my current Varnish config:
> 
> backend web1 {
>   .host="10.7.138.21";
>   .probe = {
>                 .url = "/";
>                 .interval = 5s;
>                 .timeout = 1 s;
>                 .window = 5;
>                 .threshold = 3;
>   }
> }
> 
> backend web2 {
>   .host="10.7.136.61";
>   .probe = {
>                 .url = "/";
>                 .interval = 5s;
>                 .timeout = 1 s;
>                 .window = 5;
>                 .threshold = 3;
>   }
> }
> 
> director example round-robin {
>   {
>     .backend = web1;
>   }
>   {
>     .backend = web2;
>   }
> }
> 
> sub vcl_recv {
>   set req.backend = example;
>   set req.http.host = regsub(req.http.host, "^www\.", "");
> 
>   if (req.http.host ~ "example.com" && req.url ~ "^/corporate") {
>     set req.http.host = "corporate-stag.example.local";
>     set req.url = regsub(req.url, "corporate", "");
>   }
> 
>   if (req.http.host ~ "example.com" && req.url ~ "^/service") {
>     set req.http.host = "service-stag.example.local";
>     set req.url = regsub(req.url, "service", "");
>   }
> }
> 
> If I hit _www.example.com/corporate_ in my browser, I get the correct 
> webapp. But if I navigate, the hyperlinks are all pointed to 
> _corporate- stag.example.local_ and they never pass Varnish again.
> 
> Where is my mistake?
> 
> --
> Best regards,
> Hauke
> 
> _______________________________________________
> varnish-misc mailing list
> varnish-misc at varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc



More information about the varnish-misc mailing list