url rewrite - varnish
Paul A. Procacci
pprocacci at datapipe.com
Thu May 2 16:24:40 CEST 2013
On Tue, Feb 05, 2013 at 10:29:03AM +0000, nic?e lenny bessay wrote:
> Hi Sir,
>
> I'm having problem rewriting the request from varnish to query the backend.
>
> Here is what varnish receive ==>
>
>
> http://cmsfoqua:8180/vgnExtTemplating/stresource?SecurityKey=lVPNsLcf&SiteName=axabanque&ServiceName=DetailLAB&Language=fr&ResourceName=Entete&TTL=3600&CIBLAGE=
>
> And I would like varnish to rewrite the url like this (http://cmsfoqua/xml/DetailLABEntete.xml) , then call the backend.
>
> Here is my rule in vcl_recv subroutine:
>
> set req.url = regsub(req.url, "^/vgnExtTemplating/stresource.([&?]SecurityKey=([a-zA-Z0-9])|[&?]SiteName=([a-zA-Z])|[&?]ServiceName=([a-zA-Z])|[&?]Language=([a-zA-Z])|[&?]ResourceName=([a-zA-Z])|[&?]TTL=([0-9])|[&?]CIBLAGE=([a-zA-Z]))*", "/xml/\1\2\4.xml");
>
> Here is actually what the backend get : /xml/.xml
>
> Please, Help!!!!
>
I'm not entirely sure if you can chain regsub's together as I've never done so (you probably can),
but the following (or similar) can pull the values you need from the url.
if(req.url ~ "^/vgnExtTemplating/stresource\?"){
set req.url = "/xml/" + regsub(req.url, ".*SecurityKey=([^&]+).*", "\1") + regsub(req.url, ".*SiteName=([^&]+).*", "\1") + regsub(req.url, ".*Language=([^&]+).*", "\1") + ".xml";
}
If that doesn't work, you can do something similar to the following:
if(req.url ~ "^/vgnExtTemplating/stresource\?"){
set req.http.X-SecurityKey = regsub(req.url, ".*SecurityKey=([^&]+).*", "\1");
set req.http.X-SiteName = regsub(req.url, ".*SiteName=([^&]+).*", "\1");
set req.http.X-Language = regsub(req.url, ".*Language=([^&]+).*", "\1");
set req.url = "/xml/" + req.http.X-SecurityKey + req.http.X-SiteName + req.http.X-Language + ".xml";
remove req.http.X-SecurityKey;
remove req.http.X-SiteName;
remove req.http.X-Language
}
Once variable negative lookbehind assertions are implemented in PCRE, you'd be able to
accomplish this with a one-liner. Hope that helps.
~Paul
________________________________
This message may contain confidential or privileged information. If you are not the intended recipient, please advise us immediately and delete this message. See http://www.datapipe.com/legal/email_disclaimer/ for further information on confidentiality and the risks of non-secure electronic communication. If you cannot access these links, please notify us by reply message and we will send the contents to you.
More information about the varnish-misc
mailing list