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 abc.com and xyz.com, so that when users browse http://www.abc.com or http://www.xyz.com, the system displays the respective home pages of companies ABC and XYZ, even though the companies have the same IP address (220.127.116.11). 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:
www.abc.com. IN A 18.104.22.168
www.xyz.com. IN CNAME www.abc.com.
(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 22.214.171.124. Now whether you ping www.abc.com or www.xyz.com, you obtain the same response: Reply from 126.96.36.199.
Set Up the Document Root
In your NT Web server, set up the document root directory, e:\, for the IP address 188.8.131.52. Create two subdirectories, e:\abc and e:\xyz, for the domains abc.com and xyz.com, 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:\\www.abc.com or http:\\www.xyz.com, 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:
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=http://www.xyz.com/xyz/index.htm\n\n" );
starts the URL link http://www.xyz.com/index.htm 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
Users browsing http://www.abc.com or http://www.xyz.com 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.
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 abc.com. (Alternatively, you can put the company-specific index.htm file in subdirectory e:\abc with the statement location.href="http://www.abc.com/abc/index.htm".)
This script can make the single-address virtual domain setup user-transparent; that is, when you use a compatible browser to browse the URL http://www.abc.com based on this setup, the effect will be the same as browsing a URL whose setup is based on multiple IP addresses.