PDA

View Full Version : Subdomain



jetalomar
July 16th, 2001, 20:47
is there a script to make subdomain ?

keith
July 16th, 2001, 23:51
if you'd want to use a cgi script using http_host, you'd have to have a wildcarded domain first off.

ok, let's say you have an ip address, and you point jetalomar.dhs.org and jeta.ath.cx at the ip address.

then you set up the following addresses:
jetalomar.dhs.org
jeta.ath.cx
links.jetalomar.dhs.org

this is how you'd redirect them.


to have the domain appear to actually be hosted on it's own space [ie: jetalomar.dhs.org shows jetalomar.dhs.org], you'd use this code:



#!/usr/bin/perl
$host = $ENV{'HTTP_HOST'};

if($host =~ /links\.jetalomar\.dhs\.org/) {
open(FILE, "path/to/links.jetalomar.dhs.org.html");
@lines = <FILE>;
close(FILE);
print "Content-type: text/html\n\n";
foreach $curline (@lines) {
print "$curline";
}
exit;
}

if($host =~ /jetalomar\.dhs\.org/) {
open(FILE, "path/to/jetalomar.dhs.org.html");
@lines = <FILE>;
close(FILE);
print "Content-type: text/html\n\n";
foreach $curline (@lines) {
print "$curline";
}
exit;
}

if($host =~ /jeta\.ath\.cx/) {
open(FILE, "path/to/jeta.ath.cx.html");
@lines = <FILE>;
close(FILE);
print "Content-type: text/html\n\n";
foreach $curline (@lines) {
print "$curline";
}
exit;
}

print "Location: http://default.domain.if/all/others/fail.htm\n\n";



to redirect to a subdirectory [ie: jetalomar.dhs.org goes to jetalomar.dhs.org/jetalomar/], use the following code:



#!/usr/bin/perl
$host = $ENV{'HTTP_HOST'};

if($host =~ /links\.jetalomar\.dhs\.org/) {
print "Location: http://links.jetalomar.dhs.org/links/\n\n";
exit;
}

if($host =~ /jetalomar\.dhs\.org/) {
print "Location: http://www.jetalomar.dhs.org/jetalomar/\n\n";
exit;
}

if($host =~ /jeta\.ath\.cx/) {
print "Location: http://www.jeta.ath.cx/jeta/\n\n";
exit;
}

print "Location: http://default.domain.if/all/others/fail.htm\n\n";



the one big thing to remember is any subdomains you set up [ie: links.jetalomar.dhs.org] must be set up before that actual domain [jetalomar.dhs.org], or else it will not get to them in the script before getting to the actual root domain. i used fictitious domains of course, just for example.

jetalomar
July 17th, 2001, 00:05
what if i have my own domain. mvpleague.com and i want to create jetalomar.myleague.com and jet.myleauge.com?

Ted S
July 17th, 2001, 03:10
Normally your host setups subdomains for you. Most hosts charge a small fee per subdomain. If you have a site control panel, try using it.

keith
July 17th, 2001, 17:58
#!/usr/bin/perl
$host = $ENV{'HTTP_HOST'};

if($host =~ /jetalomar\.myleague\.com/) {
open(FILE, "path/to/jetalomar.myleague.com.html");
@lines = <FILE>;
close(FILE);
print "Content-type: text/html\n\n";
foreach $curline (@lines) {
print "$curline";
}
exit;
}

if($host =~ /jet\.myleague\.com/) {
open(FILE, "path/to/jet.myleague.com.html");
@lines = <FILE>;
close(FILE);
print "Content-type: text/html\n\n";
foreach $curline (@lines) {
print "$curline";
}
exit;
}

if($host =~ /myleague\.com/) {
open(FILE, "path/to/myleague.com.html");
@lines = <FILE>;
close(FILE);
print "Content-type: text/html\n\n";
foreach $curline (@lines) {
print "$curline";
}
exit;
}

print "Location: http://default.domain.if/all/others/fail.htm\n\n";


or:



#!/usr/bin/perl
$host = $ENV{'HTTP_HOST'};

if($host =~ /jet\.myleague\.com/) {
print "Location: http://jet.myleague.com/jet/\n\n";
exit;
}

if($host =~ /jetalomar\.myleague\.com/) {
print "Location: http://jetalomar.myleague.com/jetalomar/\n\n";
exit;
}

if($host =~ /myleague\.com/) {
print "Location: http://www.myleague.com/myleague/\n\n";
exit;
}

print "Location: http://default.domain.if/all/others/fail.htm\n\n";



that was actually pretty self explanatory, from the first example...