...

View Full Version : PHP redirect script PLZ HELP ME



:mo:
06-05-2005, 03:18 PM
Hello, i've recently bought a hosting package that allows me to point unlimited domains to my site. I would like different pages to display for each domain, but I get the same site.

Could anyone PLEASE design a script that will detect what domain is in the address bar and redirect to the corresponding folder

thx

SeeIT Solutions
06-05-2005, 03:24 PM
If the hosting has cPanel included there is a redirects section that allows you to do this easily.

delinear
06-05-2005, 03:30 PM
I think you can detect this through $_SERVER['SERVER_NAME'] or $_SERVER['HTTP_HOST']

:mo:
06-05-2005, 03:39 PM
If the hosting has cPanel included there is a redirects section that allows you to do this easily.



it doesnt :( unfortunately



thx 4 ur help anyway

:mo:
06-05-2005, 03:44 PM
I think you can detect this through $_SERVER['SERVER_NAME'] or $_SERVER['HTTP_HOST']


thx, but i'm not very good with php



if ($_SERVER['HTTP_HOST'] == "www.mydomain.com")
{
//then what
}


// i suppose ill have lots of elses underneath for al my domains


3 Questions

1.)Could somebody do it for me? please
2.)If not, is that right?
3.)How do I do the redirect bit?

delinear
06-05-2005, 03:52 PM
If you just want to do a very simple redirect from index.php in the root to an index file in a sub directory (which I think will be the best option if you're still learning php) then you could do something like this:


if(strpos($_SERVER['HTTP_HOST'], 'domain1.com')) {

header('Location: directory1/index.php');

} elseif(strpos($_SERVER['HTTP_HOST'], 'domain2.com')) {

header('Location: directory2/index.php');

}

Although I'm sure there is a better solution using Apache to determine the domain and automatically show the correct sub directory, but I wouldn't know enough about Apache to be much help there.

:mo:
06-05-2005, 03:54 PM
thx :thumbsup: :thumbsup: :thumbsup: :thumbsup: :thumbsup: :thumbsup:


um.........will that work when there is www. or http:// in front?

delinear
06-05-2005, 04:00 PM
It should do, strpos() will determine if the domain appears anywhere within the $_SERVER['HTTP_HOST'] variable, so by leaving off the http and www parts you will catch anyone who arrives at the page without typing those parts too (hopefully!).

:mo:
06-05-2005, 04:04 PM
It should do, strpos() will determine if the domain appears anywhere within the $_SERVER['HTTP_HOST'] variable, so by leaving off the http and www parts you will catch anyone who arrives at the page without typing those parts too (hopefully!).

i havent had any probs yet :thumbsup:


thx again



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum