Re: virtual hosting problem

Austin S. Lin (austin@al2.com)
Sat, 19 Sep 1998 22:18:17 -0400 (EDT)


On Sat, 19 Sep 1998, Troy High wrote:

> So if I have three host.domain combinations pointing to the same
> ip address and I request "/" how does the server know what
> /index.html to send.

Just add a 'Host: virtual.somewhere.something[:port]' header to your
request object before making the request.  I don't know what other
servers do, but Apache (seems to) use this for its name-based virtual
hosting.

Here's a simple example:

  #!/usr/local/bin/perl -w

  use strict;
  use LWP::UserAgent;
  use HTTP::Request;

  my $ua       = LWP::UserAgent->new();
  my $request  = HTTP::Request->new( GET => 'http://planetperl.com/');

  # apache looks at the Host header for name-based virtual hosting...
  $request->push_header( Host => 'planetperl.com' );

  my $response = $ua->request($request);

  print $response->as_string();


- Austin
  $_@planetperl.com