Page 1 of 1

website redirection

Posted: Tue Sep 27, 2005 4:24 am
by lostinphp
i have this old website which does not exist anymore eg.www.something.fr/index.php.
when a user enters the old website i want it to be automatically redirected to the new one..say http://www.something.com.
i suppose the codin goes into the header part.;
but i dont have any idea as to how it shud be done.
if anyone here can help me out..it wud be nice..
thank u

Posted: Tue Sep 27, 2005 4:28 am
by shiznatix
header("location: http://www.newsite.com");

Posted: Tue Sep 27, 2005 4:34 am
by CoderGoblin
Or user server side redirects rather than php.

Posted: Tue Sep 27, 2005 5:00 am
by shiznatix
ya but if you have the server redirect you when the user hits the back button on their browser it will keep redirecting them to the new site, you would have to hit the back button ultra fast or retype in the url. annoying

Posted: Tue Sep 27, 2005 6:17 am
by Jenk
Don't forget to use exit():

Code: Select all

<?php 
header('Location: http://www.somesite.com');
exit(); //to prevent anything else being processed

?>
So that anything else on the page does not get processed when it doesn't need to, thus saving resources :)

Posted: Tue Sep 27, 2005 6:31 am
by patrikG
Jenk wrote:Don't forget to use exit():

Code: Select all

<?php 
header('Location: http://www.somesite.com');
exit(); //to prevent anything else being processed

?>
So that anything else on the page does not get processed when it doesn't need to, thus saving resources :)
How would that happen? Redirect directs immediately, unless you have any output prior to header() which invalidates the function and produces an error.

Posted: Tue Sep 27, 2005 6:46 am
by Jenk
The PHP process will continue to process any script after the header is sent :)

When you put, for example, http://mysite.com/index.php all that does is tell the Webserver to run the script. If the script outputs anything, then it will - one of those could be the redirect header. All the redirect header does is tell your browser to look else where.

The webserver will continue to process whatever else is within that file :)

Posted: Tue Sep 27, 2005 7:06 am
by shiznatix
this is true.

Code: Select all

header("location: http://www.google.com");
header("location: http://www.devnetwork.net");
if you run that script you will end up at devnetwork and not at google

Posted: Tue Sep 27, 2005 7:08 am
by patrikG
wow. Look at that. Over four years of PHP and I never knew.

Posted: Tue Sep 27, 2005 7:32 am
by shiznatix
haha. learn somthing new every day :lol: