Hi Drew,

My site has several domains that lead into it and I had the same problem
with cookies that I fixed this way.

Here's how I ended up doing the redirections using mod_rewrite and a perl
script (which needed to be portable in my case).  This could have probably
been done simpler and more effectively but I needed to guarantee that all
FORM variables were passed along seemlessly to the target domain and have
the script run correctly.

CAVEATS:  The script treats a FORM variables in a hash fashion so it doesnt
deal with multi-selects

In httpd virtual host section:

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME}       (.+)
RewriteRule ^/cgi-bin/(.+)
http://www.condoms.net/cgi-bin/nph-redirect.cgi?URI=%1 [P,QSA]
RewriteRule ^/(.*)                   http://www.condoms.net/$1 [R]

The script nph-redirect.cgi:

#!/usr/bin/perl
use strict;
use CGI;

my $cgi                              = CGI->new;

my %form;
my $query_string;

# get a list of all of the form and query string fieldnames
my @form                             = $cgi->param();
my @url_params                       = $cgi->url_param();

# add all of the form variables to form
map                                  { $form{$_}       = $cgi->param($_); }
@form;

# add all of the query string vars to form
map                                  { $form{$_}       =
$cgi->url_param($_); } @form;

# get domain and uri
my $request_uri                      = $form{'URI'}    || '';
my $domain                           = $form{'DOMAIN'} ||
"http://www.condoms.net/";

# create the query string
foreach (keys %form) {

   next                              if (uc($_) eq 'SUBMIT' || uc($_) eq
'URI' || uc($_) eq 'DOMAIN');
   $query_string                    .= "&$_=$form{$_}";

}

# remove the leading & because of above loop (could do with counter above
but this is easier :)
$query_string                        =~ s/^&//;

# add the ? if the query string actually has something
$query_string                        = "?$query_string" if ($query_string
!~ /^\s*$/);

my $url                                   = "$domain$request_uri$query_string";

$url                                 =~ s#/+#/#g;
$url                                 =~ s#(https?:)/#$1//#;

print $cgi->redirect(-location => $url,
                     -nph      => 1);



At 05:29 PM 04/06/00 -0400, you wrote:
>Kee,
>
>I'm about to that point. What is the easiest way to do this? I have one
>IP for the domain. Should I have my scripts check SERVER_NAME & do a
>redirect? BTW, I have complete control over the box so I can do what I
>want. :-)
>
>Kee Hinckley wrote:
>
>> As a complete aside to your aside, I recommend against having two
>> domains point to the same site.  Make the non-www one redirect to the
>> correct one.  Otherwise you are going to get indexed twice by the
>> search engines (and twice as often) which makes the search results
>> look messy, and have less options to change what domain does what in
>> the future.
>
>
>-- 
>Drew Taylor
>Vialogix Communications, Inc.
>501 N. College Street
>Charlotte, NC 28202
>704.370.0550
>http://www.vialogix.com
>
>

Reply via email to