To read the article online, visit http://www.4GuysFromRolla.com/webtech/072700-1.shtml

Hosting Multiple Domains on one IP Address

By Erick Stover


You know, I thought I was saving money. It was only a one-time fee of $10.00 for parked domains, and a monthly $20.00 fee per domain to have a complete sub domain. At the moment, I have about six different domains in my name. This was not a tough decision to make. There was one little problem, though. All of these domains pointed to the same IP address! No matter what domain name a user typed in, it went to the same site. What was a little code guy to do? Well, he would code. And code he did.

I'm sure SOME of you out there have been in a similar situation at one time or another. You need a seamless way of getting the user to the appropriate area. You also need to have different meta tags depending on the site. After all, you want all your sites on the search engines, right?

I didn't want a page that would use Response.Redirect to send them where they want to go. That takes too long to load plus they can see the redirect. I wanted one Page that just displays the appropriate code. Then, in a strange whispering voice (that sounded strangely similar to that voice in Field of Dreams), I heard the word "Frames". THAT's IT!!! I'll just create a single framed frameset and just set the frame src equal to whatever page I want!. There's no freaky-looking reload and the entire site address is easily masked. Boy I'm tired of being this good.

A number of sites run by Charles Carroll use the Response.Redirect method. For example, LearnASP.com, ASPLists.com, and ASPNG.com all point to the same IP address. If you visit ASPNG.com, you are automatically redirected to http://www.aspng.com/aspng/. Similarly, If you visit ASPLists.com, you are automatically redirected to http://www.ASPLists.com/ASPLists/. To learn how Charles handles this, be sure to read his tutorial: Using Server Variables to Determine Domain.

Another (non-ASP) solution is to use Host Headers. For a discussion on using Host Headers be sure to read Robert Black's article: Using Host Headers to Allow for One I.P Address to Host Multiple Domains!

OK, enough of an introduction, let's get to the code! I started with the domain detection.

<%
dim file 'the file name
dim siteId 'just a number I assigned to each site.

'Now I use the request serverVariables to get the address
'they typed in their browser.
if Request.ServerVariables("SERVER_NAME") = "www.dragonden.net" or _
    Request.ServerVariables("SERVER_NAME") = "dragonden.net" then
  'Quick note, you have to specify the two different versions of your
  'domain name.  Not everybody uses the "www", others use it religiously.
  'The server can't tell the difference between the two unless you give
  'it a hint.
  file = "dn7.asp" 
  siteId = 1
elseif Request.ServerVariables("SERVER_NAME") = "www.3dguru.com" or _
    Request.ServerVariables("SERVER_NAME") = "3dguru.com" then
  file = "http://www.mp3.com/3dguru/"
  siteId = 2
elseif Request.ServerVariables("SERVER_NAME") = "www.darkhorizon.org" or _
    Request.ServerVariables("SERVER_NAME") = "darkhorizon.org" then
  file = "dh/index.asp"
  siteId = 3
elseif Request.ServerVariables("SERVER_NAME") = "www.dragondes.com" or _
    Request.ServerVariables("SERVER_NAME") = "dragondes.com" then
  file = "dd/index.asp"
  siteId = 5
else
  'if it can't figure out what they typed, just send them to the main area
  file = "dn7.asp" 
  siteId = 1
end if
%>

The main part is done. Now we need to do something about those pesky search engines. As far as I know, search engines access your site much in the same way that a browser accesses it. So I make a case statement with the meta tags. I also threw in the title tags for kicks.

<html>
<head>
<%Select Case siteID%>
<%Case 1%>
<meta http-equiv="Keywords" content="rant dragon net editorial 
background photoshop tutorials poetry stories flash animation">
<meta http-equiv="Description" content="The Homepage for Dragon Net.
A society of web designers and computer experts. This is my world.">
<title>Dragon Net</title>
<%Case 2%>
<meta http-equiv="Keywords" content="techno music electronic industrial
trance house">
<meta http-equiv="Description" content="The Music Maker of Dragon Net">
<title>3D Guru</title>
<%Case 3%>
<meta http-equiv="Keywords" content="photoshop graphic design animation 
presentation 3d studio max art">
<meta http-equiv="Description" content="The Graphic artists of Dragon Net">
<title>Dark Horizon Studios</title>
<%Case 4%>
<meta http-equiv="Keywords" content="asp html coldfusion xml dhtml
javascript vrml visual basic access microsoft jscript internet explorer
netscape">
<meta http-equiv="Description" content="The Code Masters of Dragon Net">
<title>Dragon Designs</title>
<%End Select%>
</head>

Finally, we create the frameset. This was a lot easier than I thought. The one thing to remember is that you need to use the Frameset tags instead of the body tags.

<frameset rows="99%, 1%" frameborder="NO" border="0" 
framespacing="0">
<frame src="<%=file%>">
<frame src="blank.asp">
</frameset>
<noframes> <!--For early browsers that can't handle frames. Let
those users know how you feel.-->
<body bgcolor="white" text="black">
This site uses frames. If you don't have a frames capable browser,
go get one. <br>
Otherwise, you're not allowed on my site. Go! Get outta here!!!
</body>
</noframes>
</html>

There you have it, a simple page that can save you some money, or at least a few headaches!

Happy Programming!


Attachments:

  • Download the ASP source code in text format
  • Read Charles Carroll's tutorial: Using Server Variables to Determine Domain


    Erick Stover, age 21, is the webmaster and designer of Dragon Net. He is also the president of Dragon Designs and Dark Horizon Studios.


  • Article Information
    Article Title: Hosting Multiple Domains on one IP Address
    Article Author: Erick Stover
    Published Date: Thursday, July 27, 2000
    Article URL: http://www.4GuysFromRolla.com/webtech/072700-1.shtml


    Copyright 2017 QuinStreet Inc. All Rights Reserved.
    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers