URL Rewriting

Dag-Erling Smørgrav des at linpro.no
Sat Mar 8 11:38:00 CET 2008


"Alex Harrington" <alex at longhill.org.uk> writes:
> I'm hoping I can use Varnish to sit between the web server and my users
> to disguise the subfolders in to separate domains - eg
>
> Client URL => Backend URL
> http://example.com => http://example.com
> http://example.com/index.phtml?d=12345 =>
> http://10.108.1.59/index.phtml?d=12345
>
> http://www.deansleisurecentre.com => http://10.108.1.59/dlc
> http://www.deansleisurecentre.com/index.phtml?d=12121 =>
> http://10.108.1.59/index.phtml?d=12121
>
> http://www.woodingdeanyc.org.uk => http://10.108.1.59/wyc
> http://www.woodingdeanyc.org.uk/index.phtml?d=54321 =>
> http://10.108.1.59/index.phtml?d=54321

Yes, Varnish can do that.

> sub vcl_recv {
> 	if (req.http.host ~ "^(www.)?deansleisurecentre.com") {

you'll want to terminate that regexp with $.

> 		set req.http.host = "deansleisurecentre.com";
> 		set req.http.url = regsub(req.url, "^/$", "/dlc");
> 	}

The rest of your vcl_recv is redundant and will cause trouble if / when
you upgrade to a newer version.

> I've edited my local PCs hosts file to point deansleisurecentre.com to
> the box running Varnish, however when I access deansleisurecentre.com, I
> get http://example.com instead without the rewrite.

You need to set up a separate backend for deansleisurecentre.com.

DES
-- 
Dag-Erling Smørgrav
Senior Software Developer
Linpro AS - www.linpro.no



More information about the varnish-misc mailing list