PERL
if( $ENV{"SERVER_NAME"} =~ /domain\.com$/i ) {
print "HTTP/1.1 302\r\nLocation: /usr/account\r\n";
}
else {
print "Content-type:text/html\n\n";
print "You came to unknown domain. Please choose one of the following:<br>";
print "<a href='http://www.domain.com'>http://www.domain.com</a><br>";
}
ASP
This is an example of
default.aspthat will redirect the requests for different domains to appropriate directories.
<%
If InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("domain1.com") ) > 0 Then
Response.Redirect("/directory1")
ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("domain2.com") ) > 0 Then
Response.Redirect("/directory2")
ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("domain3.com") ) > 0 Then
Response.Redirect("/directory3")
Else
Response.Write("You came to an unknown domain.")
End If
%>
Notes:
COLDFUSION
This is an example of
default.cfmthat will redirect the requests for different domains to appropriate directories.
<CFIF FindNoCase("domain1.com","#CGI.SERVER_NAME#") GT 0>
<CFLOCATION URL="/directory1">
<CFELSEIF FindNoCase("domain2.com","#CGI.SERVER_NAME#") GT 0>
<CFLOCATION URL="/directory2">
<CFELSEIF FindNoCase("domain3.com","#CGI.SERVER_NAME#") GT 0>
<CFLOCATION URL="/directory3">
<CFELSE>
You came to unknown domain.
</CFIF>
Notes:
But.... it would not work for example.com, and example1.com, unless you could talk your web host into adding DNS entries for all your domains and map them all to your one IP address.
IMO you are asking for trouble in using your domains in this way.
if you get caught breaking the hosts terms and conditions and cheating them out of money, at best you'll get poor service (slow or no support) and at worst you could get shut down without notice or explanation. terminations can be extremely costly in terms of lost business. you could theoretically also find yourself on the receiving end of a claim for non-payment (although i don't actually know of any such cases).
if i catch someone cheating me, i normally wait until googlebot comes around then terminate. the couple of days it takes them to find out what's happened then get the site back online with another host is normally long enough to destroy their listings in google for a month. i know a number of other web hosts that also play the "you screw us and we'll screw you" game and the beauty of it is that site owners simply cannot prove a thing or do anything about it.
don't be surprised as well to find that if you get shut down for defrauding a web host, that whoever you move the site to will "discover" why you were shut down and they may refuse to host your site. at the very least they could be watching and waiting.
hosting is very cheap - 12 months hosting costs less than a good night out. there's no real excuse for defrauding web hosts. you play the game and pay the hosts, and they'll play the game and give you the service and support you need.
look for hosts that allow multiple sites on one account. these are normally known as reseller accounts or multi-site accounts. pay the fees, stay legal, and you can't go wrong.
Crazy_Fool - If I pay for web hosting service that is under utilized it is reasonable to maximize the allowed bandwidth by directing more traffic to the web host. Only 1Gb out of 5Gb is being utilized. Why not point three or four domains to it? As Air said, it is not possible to set it up the way I described anyway. My web host wants $20 to point a domain to the IP. Who is cheating whom?
how about that $20 thats sitting in your bank account doing nothing? that's under utilized. would you likewise agree to someone helping themselves to that?
>>My web host wants $20 to point a domain to the IP. Who is cheating
>>whom?
if you don't like it, find another host. don't defraud a host just because you disagree with their pricing structure. there are thousands of hosts out there that will allow what you need at prices you can afford.
There's a few. The fact that all requests to all domains will be handled by one script will cause a performance problem for your sites' response times. Most machines are set to limit a single process (or the same process many times) from monopolizing the machine. Your script would fall into this category.
The way the content is pointed to is by redirecting the request, this sets a redirection code that can trigger specific actions to a search engine spider, some browsers, and your logs will be a mess.
If you decide to run certain scripts on those domains you may find that they will not work. Since a script is already handling all page requests this may be unforseen to the script you want to use, consequently you may find configuration difficult, and operation faulty.
Then there's the stuff Crazy_Fool mentions, which distilled, is that hosts will target you for special attention if you use too much resources. It may not sound right, but most hosts offer hosting plans with space and bandwidth limits that are set to be competitive, but they know that very few will come anywhere close to those limits. If you do, expect to be asked to move to a higher priced plan or to a new host.