how to redirect based on calling domain?

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
wscottpadgett
Forum Newbie
Posts: 4
Joined: Mon Jun 07, 2004 9:33 pm
Location: Charleston, SC and Boston, MA

how to redirect based on calling domain?

Post 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
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

try $_SERVER['HTTP_HOST'];
wscottpadgett
Forum Newbie
Posts: 4
Joined: Mon Jun 07, 2004 9:33 pm
Location: Charleston, SC and Boston, MA

brilliant!

Post 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.
Post Reply