Page 1 of 1

how to redirect based on calling domain?

Posted: Mon Jun 07, 2004 11:29 pm
by wscottpadgett
Hi guys,

I just set up a dynamic DNS account and I have two domains that get pointed to my root directory on my Mac so that I can allow people http access to certain stuff.

I want to send those folks who use one of the domains to one index page while those using second domain go to a different index. I thought I could just do this by running a conditional based on the domain that exists in the file request, and then popping a PHP header to the appropriate index page.

Something like:

if ($_SERVER['HTTP_REFERER'] == "domainone.net")
{

header ("Location: http://domainone.net/clients.html");

}

else if ($_SERVER['HTTP_REFERER'] == "domaintwo.net")

{

header ("Location: http://domaintwo/me.html");

}

Problem is, of course, the above won't work as written because there is no referrer in a direct request to look at.

Is there some SERVER variable that I just can't think of or find that will allow me compare the domain name to a condition to try to run this the way i want? I was trying to possibly use the ModRewrite module to do the redirect also, but seems like it's just as dependent on the standard SERVER variables as to what it can read in a calling URL.

Anyone help??

Thanks!!! I'm baffled right now.


-Scott

Posted: Mon Jun 07, 2004 11:32 pm
by andre_c
try $_SERVER['HTTP_HOST'];

brilliant!

Posted: Mon Jun 07, 2004 11:43 pm
by wscottpadgett
thanks! that did the trick. the documentation on PHP.net on that server variable was a little vague -- i should have guessed that was the one.