[thelist] Virtual directories in IIS

Jason Handby jasonh at pavilion.co.uk
Wed Jun 18 06:55:02 CDT 2003

Hi David,

> following on from an earlier post of mine. [pros/ cons of using relative
> links] i am trying to configure IIS on a test webserver to allow
> my links to
> work.
> basically i have several websites running on my machine, and i want links
> like /images/foo.png to work. even though the image is physically
> located in
> \inetpub\wwwroot\mytestsite\images\foo.png
> from the previous posts, i am guessing this is done in apache
> using virtual
> hosts, and i am trying to find the equivalent in IIS.

Virtual hosts and virtual directories both exist in IIS. They're different
things, though...

IIS calls a virtual host a "web site". You can have multiple web sites
defined within IIS, each with its own root folder.

When it receives an incoming request for a page, IIS has to work out which
website the request is for. So when you set up your sites you have to give
IIS a way to distinguish them. (You do this in the "Website identification"
section of the "Web Site" tab in "Properties".) One way is to assign each
web site to a separate IP address on your server (and then set up your DNS
so that each site name maps to a separate IP). This is what's called
"IP-based virtual hosts" in Apache. But you probably don't want to do it
this way.

The other way is to tell IIS what the host header name (e.g.
www.mysite.co.uk) for each site is. The client's browser will supply the
name of the server they're trying to connect to in the headers of the HTTP
request. This means you can set all your DNS entries for all your websites
to point to one IP address for your server, leaving IIS to work out which
request is for which site by looking at the request headers. To set the host
header name in IIS, go to "Properties | Web Site", click "Advanced..." in
the "Website identification" section, and edit the entry in the top list to
add the host header name. This is what Apache calls "name-based virtual
hosts". You should almost always use this; it's much nicer.

Virtual *directories* in IIS allow you to map an actual directory onto a
virtual directory in your website. So for example, if you create a virtual
directory called "images" from a folder anywhere on your server, the
contents of that folder will appear at http://www.mysite.co.uk/images/ even
though they're not physically located in the images/ subfolder of your web
site's root folder.

> i have tried moving the mytestsite directory to a different location and
> setting up a virtual directory in IIS, however the image is not being
> displayed, and if i look at the properties the webpage is expecting the
> image to be found in http://localhost/images/foo.png

If I've understood what you're trying to do, I think you just need to set up
a web site in IIS for your project.

If you're running IIS on your local machine you can set it up as follows.

Create a new web site in IIS for your project. Set a host header name of
"mytestsite" (or whatever you want). Set the IP address to be
which is your local loopback address.

Edit the "hosts" file, which you will find at
C:\WINNT\System32\Drivers\etc\hosts (this path may be different for you
depending on where you installed Windows). There should already be a line
for which looks like this:       localhost

Add the name of your test site onto the end of this line, so it looks like
this:	    localhost mytestsite

Et voila. Now when you put http://mytestsite/ into Internet Explorer it will
connect to your PC running IIS, and IIS will map the site name onto the new
website you've created.


More information about the thelist mailing list