Web Hosting Talk







View Full Version : multiple domains redirection


gthorley
02-17-2001, 04:22 PM
A while ago the following script placed in index.cgi was posted in a thread which directed domain names into specific folders. It required that an .htaccess file be set up pointing to index.cgi as the default opening file.



#!/usr/bin/perl

$home = "index.html";


%domains = (
'www.domain1.com' => 'domain1/',
'www.domain2.com' => 'domain2/',
'www.domain3.com' => 'domain3/',
);


$server = lc($ENV{'HTTP_HOST'});if ($ENV{'HTTP_HOST'} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/){$t='/'}else{if
($server !~ /^www./){$server = 'www.' . $server;}}@domains = keys(%domains);foreach
$domain(@domains){if ($domain eq $server){print "Location:
http://${server}/$domains{$server}\n\n";$match="yes";last;exit}}unless ($match){print "Location:
http://$server/$home\n\n"; exit}

exit;

I have tried to set this up but cannot get it to work. In my case I only have a http://www.domain1.com set up and this is directed to the main site by IP pointing from mydomain.com.

Both .htaccess and index.cgi are working but the second domain pointed to my IP keeps loading in whatever index file I set up for the primary domain.

Anyone have any ideas as to what can be done. My suspicion is that the script reads the domain directed by mydomain.com as my hosted domain and then directs it based on that info. The interesting thing is that location box shows the directed domain as follows http://www.domain1.com/index.shtml

elsmore1
02-17-2001, 05:55 PM
Can you give more info? Like the domains involved?

gthorley
02-17-2001, 06:23 PM
The hosted domain is http://www.artbyjudy.com and the domain being redirected is http://www.ourartpage.com.

So in the script I have
'www.ourartpage.com' => 'ourartpage/',

elsmore1
02-17-2001, 06:47 PM
The script you have will not redirect IP address requests, which is what you are getting from mydomain.com. You would either need to get mydomain.com to point to the subdirectory you want displayed for that domain (I don't know if they do that or not) or use a script simialr to the one you have which would check HTTP_REFERER instead of the HTTP_HOST, and then deliver the page you want displayed for referals from mydomain.com.

As it is, you will be getting requests from the mydomain.com frameset as IP address requests and your script doesn't do anything with those, except to print the default location.

If you were only ever going to have the one domain to re-direct, you could modify the last line of the script you have (or the line for the IP address match) to send all requests coming in as the IP address to the redirected domain.

HTH

gthorley
02-18-2001, 12:07 AM
So the problem is the script needs to check and if http_host is http://www.artbyjudy.com it should redirect to index.html and if not it checks http_referrer and redirects to what corresponds which would be a sub folder.

I haven't got a clue how to amend this script. Would anyone care to give it a try or know of a script that will do this.

elsmore1
02-18-2001, 01:51 AM
This ought to work...


#!/usr/bin/perl
$home = 'index.html';
%domains = (
'ourartpage.com' => 'ourartpage/'
);

$host = lc $ENV{'HTTP_REFERER'};
$host =~ s/^www\.//i;

if (defined $domains{ $host } ) {
print "Location: http://$ENV{'SERVER_ADDR'}/$domains{ $host }\n\n";
}else{
print "Location: http://www.$ENV{'HTTP_HOST'}/$home\n\n";
}

exit;


[Edited by elsmore1 on 02-18-2001 at 01:06 AM]

gthorley
02-18-2001, 10:25 AM
I tried out the script this a.m. and it keeps returning an
error


Error Message: Exec format error
Error Number: 8

Appreciate the effort any thoughts on what needs to be changed.

Have tried following change to no avail

-putting http://www. in front of ourartpage.com as original script said to be sure to include the www

elsmore1
02-18-2001, 10:37 AM
"exec format error" --- make sure you upload it in ASCII/text mode, chmod it to 755.
make sure that the #!/usr/bin/perl is the FIRST line, and that there is nothing else on that line.


Do not put the "www." on the front of the domains on this script, as I wrote it to check against the list without the "www." there.

If you try everything above and it still won't go, you can email me for further help.