Setting up virtual domains in Windows NT is straightforward. In September 1996 ("How to Set Up Virtual Domains"), I described how to assign a unique IP address to each domain. However, in practice, you might want to set up domains that share an IP address, for several reasons. For example, because of a bug in the NT 3.x design, you can add only about 14 different IP addresses in that system unless you have installed Service Pack 5. In NT 4.0 Workstation, you can add about 10 IP addresses in the system; if you add more, you risk running into legal battles with Microsoft. Moreover, many Web servers-- in particular, those running on Windows 95 or on the Macintosh--do not support multiple IP addresses. In these circumstances, sharing an IP address for different domains is the best solution for setting up virtual domains. Let's explore how sharing an IP address works and look at two ways of setting up virtual domains with one IP address.

Our goal is to set up different domains, such as and, so that when users browse or, the system displays the respective home pages of companies ABC and XYZ, even though the companies have the same IP address ( You can accomplish this feat with a simple script. The method works for more than two domains, too. I used Computer Software Manufaktur's Alibaba 2.0 Web server running NT Workstation to illustrate the techniques, but you can use the same method with Microsoft Internet Information Server (IIS) or any other contemporary Web server.

The Domain Name System Name Server
First, set up the Domain Name System (DNS) name server in your Network properly. To make two domains share an IP address, you can set up a canonical name (CNAME) for aliases. (A CNAME is the official name of the system host and is specified in the address (A) record for the host.) Create a CNAME record for each alias that shares the address. When a name server looks up a host name or domain name and finds a CNAME record, the server replaces the host or domain name with the CNAME and looks up the CNAME. If you use the Berkeley Internet Name Domain (BIND) software in your name server, you must add the following two entries to the primary named file: IN A IN CNAME

(BIND, usually included in UNIX-based operating systems, is the basis for the Windows NT 4.0 DNS. See Spyros Sakellariadis, "Configuring and Administering DNS," August 1996.) In the NT machine, add the network IP address Now whether you ping or, you obtain the same response: Reply from

Set Up the Document Root
In your NT Web server, set up the document root directory, e:\, for the IP address Create two subdirectories, e:\abc and e:\xyz, for the domains and, respectively. The home pages of the two companies reside in those two subdirectories and subsequent subdirectories. For example, company ABC can set up a subdirectory e:\abc\images to hold all the images that it needs. At this point, create the default file index.htm (or the appropriate default entry file of your Web server) for a home page and put it in the document root directory. Now when users browse either http:\\ or http:\\, they will see the same home page.

To display different home pages for the two universal resource locators (URLs), you must redirect the requests to the appropriate directories and execute the correct files. A simple way to do this task is to add the appropriate index.htm file, or subdirectory, to the URL or to the link to the company on a related home page; when users request that URL or click on that link, they will go to the right subdirectory. The following sections explore two methods to make this process transparent to the user.

The CGI Method
First, let's first explore using Common Gateway Interface (CGI) scripts to redirect requests. You can automatically start a new URL by making use of the client-pull technique. In this technique, the browser either reloads the current page or loads a different page after a specified delay. In this way, Web document contents can change without action from the user. One way to redirect a URL is to edit the default start file index.htm (in e:\) so that it contains the statements:



<meta http-equiv="Refresh" content="0;url=/cgi-bin/referer.exe">




where content="0 informs the server to start (i.e., refresh) the URL specified in the line after 0 seconds (i.e., immediately). The file referer.exe is an executable CGI script that has been compiled from the C-source code (referer.c) in Listing 1 to direct the user to the correct domain.

In Listing 1, the statement


returns the link that leads to the execution of the CGI script. The function


searches for the existence of a substring that returns NULL if the substring does not exist. Through these steps, the command Refresh will start the correct home page. For example

printf( "Refresh: 0; URL=\n\n" );

starts the URL link after 0 seconds--that is, immediately.

This method is a simple way to redirect the user. You can easily modify the code to make the URL-lookup efficient when you have a large number of URLs. For example, you can put all the URLs in a table and use standard searching techniques, such as hashing or binary searching to perform a quick table lookup. Unfortunately, most browsers currently do not return the appropriate URL-referrer when you start the CGI by Refresh instead of by hand-clicking the URL link. Although I believe that Refresh will work in the future, to use the CGI method now, you must click at the prompt, and the file index.htm in e:\ will be


<a href="\cgi-bin\referer.exe">
Please click here</a>


Users browsing or will see the prompt

Please click here

You must click on this message to start the correct page. Alternatively, you can use the tag


in an HTML page to perform the page refresh.

If you want to automate the whole process to work under browsers in use today, you must use JavaScripts.

The JavaScript Method
JavaScript lets you embed JavaScript commands in an HTML page to call up the correct home page. When you use a compatible Web browser, such as Internet Explorer (IE) 3.0 or Netscape Navigator 2.0 or higher, the browser loads your JavaScript commands as part of the HTML document. You trigger the commands by clicking the buttons that Java displays on a related home page or the browser evaluates the commands as it downloads the script. Thus, the scripts can make Web pages execute dynamically. Listing 2 presents the complete JavaScript code that makes the URL-redirection transparent to the user. Place this code in the file index.htm (or the default entry file of your Web server) in the document root directory of the Web server.

When the Web browser downloads the HTML file index.htm, the browser evaluates the JavaScript code go(), which calls the function go(). The function go() calls up the correct URL link. In the function, the variable location.href contains the current URL (i.e., either or and is compared with variable x. I set x to be the string http://www.r, which has a string value between and Thus, if location.href is larger than x, the reference URL is; otherwise, it is

After determining the correct reference URL, you can redirect the browser to the correct home page by assigning the appropriate URL link to location.href. For example, the statement


automatically informs the browser to download the file index1.htm, which resides in the document root directory. This file (index1.htm) is the entry point for the home pages of the company (Alternatively, you can put the company-specific index.htm file in subdirectory e:\abc with the statement location.href="".)

This script can make the single-address virtual domain setup user-transparent; that is, when you use a compatible browser to browse the URL based on this setup, the effect will be the same as browsing a URL whose setup is based on multiple IP addresses.

I admit that this method works only if the browser supports JavaScript. For obsolete browsers, you must rely on the manual CGI method. But either method lets you stretch a limited number of IP addresses.