Page 1 of 1

Multiple domain redirect

Posted: Wed Nov 29, 2006 9:39 am
by some2
Hi,

I've a domain working on Apache/2.0.59 (Win32) mod_jk/1.2.18 PHP/4.4.4 setup. It works fine, but I recently configured another domain on the same server. Nameservers and everything is fine but the new domain points to the location of old domain.

Is there any way, using PHP, to redirect both domains to different locations?

For a single domain redirect, I used this so far:

Code: Select all

<?php
header("Location: v/index.jsp"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>

I tried this for multiple domain redirect, but it doesn't work:

Code: Select all

<?php
header("Location: http://domain1.com" . $_SERVER['HTTP_HOST']
                     . dirname($_SERVER['PHP_SELF'])
                     . "/dir/file.ext" . $relative_url);

header("Location: http://domain2.com" . $_SERVER['HTTP_HOST']
                     . dirname($_SERVER['PHP_SELF'])
                     . "/dir/file.ext" . $relative_url);
?>

Any help greatly appreciated.

Thanks.

htaccess

Posted: Wed Nov 29, 2006 10:26 am
by Jaxolotl
didn't you try to use an .htaccess file with some rules?
or you want to check the incoming trafic before redirect it?

Posted: Wed Nov 29, 2006 10:31 am
by some2
Using htaccess (on windows) would require additional settings, I believe. But yes, I want to log all incoming traffic.

headers

Posted: Wed Nov 29, 2006 10:59 am
by Jaxolotl
the script you write won't work (as I know) because you can send only one Header information at the time, you may write a kind of condition to do what you want.
something like this

Code: Select all

<?php
if(MY CONDITION){
header("Location: http://domain1.com" . $_SERVER['HTTP_HOST']
                     . dirname($_SERVER['PHP_SELF'])
                     . "/dir/file.ext" . $relative_url);
}
elseif(SECOND CONDITION){
header("Location: http://domain2.com" . $_SERVER['HTTP_HOST']
                     . dirname($_SERVER['PHP_SELF'])
                     . "/dir/file.ext" . $relative_url);
}
else{
// DO MY DEFAULT OPTION or send the default header information
}
?>
if I'm on error please correct me, got to go now but i'll be back in some hours

Posted: Wed Nov 29, 2006 8:14 pm
by some2
doesn't seem to work, both domains now redirect to a blank page. :(

Re: Multiple domain redirect

Posted: Thu Nov 30, 2006 12:52 am
by timvw
some2 wrote: I've a domain working on Apache/2.0.59 (Win32) mod_jk/1.2.18 PHP/4.4.4 setup. It works fine, but I recently configured another domain on the same server. Nameservers and everything is fine but the new domain points to the location of old domain.

Is there any way, using PHP, to redirect both domains to different locations?
Why don't you configure two virtual hosts?
NameVirtualHost *

<VirtualHost domain1:80>
DocumentRoot D:/websites/domain1
</VirtualHost>

<VirtualHost domain2:80>
DocumentRoot D:/websites/domain2
</VirtualHost>

Posted: Thu Nov 30, 2006 1:45 am
by some2
Doesn't work either. Both domains still point to the same location. :(

Posted: Thu Nov 30, 2006 2:34 am
by timvw
Ok, let's start from the beginning.

How did you configure the two domains? (dns configuration, apache configuration)

Posted: Thu Nov 30, 2006 3:35 am
by some2
DNS Configuration:

ns8.domain1.com = xx.xx.xx.89

ns1.domain2.com = xx.xx.xx.90
ns2.domain2.com = xx.xx.xx.91

Apache configuration:

Here's the httpd.conf

Redirection:

This is the index.php in the apache root:

Code: Select all

<?php
header("Location: v/index.jsp"); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>
With this, both domains currently redirect to the same jsp application (c:\www\tomcat5\webapps\v\index.jsp) whereas, the domain2.com should redirect to a different location (c:\www\tomcat5\webapps\xyz\index.jsp)


Note: I'm on windows so htaccess doesn't work, I already checked.