Any help?
Glenn Howell
webm...@cop-spot.com
Cop Spot Law Enforcement Web
www.cop-spot.com
--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content. You can SELF-APPROVE your first posting
by writing the word 'passme' on a line by itself.
Simple...
(C Example)
#include <stdio.h>
void main (void) {
if (strcmp (getenv ("REMOTE_HOST"), "some_domain.com") == 0){
printf ("Location: /index_to_use.html\n\n");
} else {
printf ("Location: /other_index.html\n\n");
}
return;
.
or something similar.. I'm sure you get the idea.
-dk
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
:I am looking to add an index.cgi to my site due to multiple domain names. I
:need the index.cgi to detect the domain requested (i.e. www.domain1.com) and
:direct it to d1index.html or d2index.html if another domain is requested.
You could use the environment variable HTTP_HOST which is sent by most
browsers and contains the requested domain. I made this script that does
just what you want:
---cut here---
#!/usr/local/bin/perl
$url="";
if($ENV{'HTTP_HOST'} eq 'sales.mycompany.com')
{$url = "/sales/"}
if($ENV{'HTTP_HOST'} eq 'www.support.mycompany.com')
{$url = "/support/"}
if($ENV{'HTTP_HOST'} eq 'yahoo.mycompany.com')
{$url = "http://www.yahoo.com/"}
if($url eq "") {$url="/index2.html"} # this is where all other domains
# will be sent
print "Location: $url\n";
print "Content-Type: text/html\n\n";
print "<HTML><HEAD><TITLE>$ENV{'HTTP_HOST'}</TITLE></HEAD><BODY>\n";
print "<A HREF=\"$url\">Click here to enter our site</A>\n";
print "</BODY></HTML>";
---cut here---
--
Thijs Kinkhorst * Jaze Web Design * ICQ 432406
th...@kinkhorst.com * http://www.jaze.net * KeyID 0x371EFCB1
-= ceterum censeo spam esse delendam - http://spam.abuse.net/ =-
You certainly could, but it's almost certainly a bad idea. Just use
a server that supports virtual hosts, and it will do all that (and
more) much more efficiently than a script.
--
Nick Kew
In article <3537AE...@webthing.com>, Nick Kew <ni...@webthing.com>
writes:
:You certainly could, but it's almost certainly a bad idea. Just use
:a server that supports virtual hosts, and it will do all that (and
:more) much more efficiently than a script.
That sure is true. Apache for example supports this nice feature. An
example of how to use this can be found in httpd.conf. Using an
index.cgi the way I suggested though, is useful if you don't have access
to httpd.conf (for example if you've got a virtual server) or if your
server doesn't support virutal hosts.
A disadvantage of both features is that the browser has to send
HTTP_HOST for it to work.
--
Thijs Kinkhorst * Jaze Web Design * ICQ 432406
th...@kinkhorst.com * http://www.jaze.net * KeyID 0x371EFCB1
-= ceterum censeo spam esse delendam - http://spam.abuse.net/ =-
:I am looking to add an index.cgi to my site due to multiple domain names. I
:need the index.cgi to detect the domain requested (i.e. www.domain1.com) and
:direct it to d1index.html or d2index.html if another domain is requested.
:Any help?
Glenn,
Here's something I wrote a while ago that you could install. A friend
of mine uses it to manage many domains parked on one IP with a
commercial ISP to save some on costs. Hope it helps. (I wrote it
long enough ago that I notice it doesn't even have -w as all my
current scripts do. I know it works for my friend, but if you have
any problems please tell me so I can improve it.)
Hmmm... The more I think about it, the more I think that it might be
a bad idea to compile CGI.pm everytime somebody hits one of these
domains. Think that through before you use this and think about
mod-perl or something...
Cheers,
Jeff
#!/usr/local/bin/perl
# redirect.pl redirects website requests according to the
# specific server name requested. This is useful when
# you have more than one domain name "parked" on an IP
# and want to display different information depending on
# what's requested.
.
# This script was written with the Clever Computers -
# http://clever.net/ environment in mind. I don't know
# that it won't work elsewhere, but if you have any problems,
# let me know.
.
# Created by Jeff Yoak - http://yoak.com/
.
# 6/14/97 - first script
.
# To Do:
.
# USAGE: CGI
.
# Definitions:
.
# redirect.config
# The redirect.config file tells redirect.pl where to send
# the browser for each specific request. It should have the
# following format:
.
# domain_name_1:file_location_1
# domain_name_2:file_location_2
# [...]
# default:file_location_3
.
# The path on the file_location must be relative to the
# directory where the script itself lives as below.
.
# yoak.com:foo/maindom/index.html
# www.yoak.com:foo/maindom/index.html
# 207.124.97.73:foo/altdom/index.html
# default:foo/error.html
.
######### WHERE IS MY redirect.config
$red_file = '/mnt/web/guide/yoak/foo/redirect.config';
#-------------------------------------------------------------------------------
use CGI;
$query = new CGI;
# Get the server name.
$server = CGI::virtual_host() or &no_servername;
# Initialize the hash of server names and locations.
open(IN,"$red_file") or &no_config;
while(<IN>) {
($s_name,$loc)=split(/:/);
chomp($loc);
$location{$s_name}=$loc;
.
close(IN);
# Print the redirect
if ($location{$server}) {
$redirect="http://$server/".$location{"$server"};
print $query->redirect("$redirect");
} else {
$redirect="http://$server/".$location{"default"};
print $query->redirect("$redirect");
.
exit(0);
##### Subroutines Follow #####
sub no_servername {
print $query->header;
print $query->start_html(-title=>'No Servername');
print '<H1>Could not find the server name.</H1>';
print $query->end_html;
.
sub no_config {
print $query->header;
print $query->start_html(-title=>'No Config File');
print '<H1>Could not read config file.</H1>';
print $query->end_html;
.
--
Jeff Yoak je...@yoak.com