Page 1 of 1
Redirecting in PHP
Posted: Thu Jun 22, 2006 11:42 am
by dirgeshp
My Question is
I have a domain name and what I wanna be able to do is. ... have users go to X.Domain.com and then have that redirect to domain.com/users/X
Can someone tell me how to do this?
x.domain.com -> domain.com/users/x
y.domain.com -> domain.com/users/y
Please reply
Posted: Thu Jun 22, 2006 11:43 am
by alex.barylski
Code: Select all
header('location: http://www.domain2.com/somedir');
Edit: You can also use a META redirect or javascript...
But i'd go with PHP example given above...it just makes life easier

Posted: Thu Jun 22, 2006 11:44 am
by dirgeshp
Yea, but where do i put that...
you have to see that users are not going to domain.com anymore they are going to x.domain.com
so where do i put that HEADER info?
Posted: Thu Jun 22, 2006 11:50 am
by Benjamin
I don't know if this will work or not, it's just some code I threw together from the php manual...
Code: Select all
$CurrentAddress = strtolower(strtok($_SERVER['SERVER_PROTOCOL'], '/')).'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
switch($CurrentAddress) {
case 'http://x.thisaddress.com':
header("Location: http://www.domain1.com");
exit();
break;
case 'http://y.thataddress.com':
header("Location: http://www.domain2.com");
exit();
break;
default:
header("Location: http://www.domain1.com");
exit();
}
Posted: Thu Jun 22, 2006 11:54 am
by dirgeshp
where do i put that code?
index.php ?
Posted: Thu Jun 22, 2006 11:55 am
by Benjamin
At the top of the page that you want to redirect, make sure there is no space before the <?php, it needs to be at the very top. If anything gets sent before the header redirect it will throw an error.
Posted: Thu Jun 22, 2006 12:00 pm
by RobertGonzalez
Can you use mod_rewrite?
Posted: Thu Jun 22, 2006 12:02 pm
by dirgeshp
how can i check to see if i can?
if so, what would i have to do...
i tried placing a script in the .htaccess file...but it screwed up everything
so i guess i might not be able to
Posted: Thu Jun 22, 2006 12:04 pm
by Benjamin
The code I posted is PHP...
It should go in the page you want to do the redirection, such as index.php, between <?php and ?> tags.
Posted: Thu Jun 22, 2006 12:11 pm
by RobertGonzalez
dirgeshp wrote:how can i check to see if i can?
if so, what would i have to do...
i tried placing a script in the .htaccess file...but it screwed up everything
so i guess i might not be able to
What was in your .htaccess file? Just putting a .htaccess file up shouldn't screw anything up unless what was in the .htaccess was not correct.