View Single Post
  #4 (permalink)  
Old 03-18-2008, 10:17 AM
wige's Avatar
wige wige is offline
Moderator
WebProWorld Moderator
 

Join Date: Jun 2006
Location: United States
Posts: 1,782
wige RepRank 4wige RepRank 4wige RepRank 4wige RepRank 4
Default Re: Problem in redirecting URL

If you do not have the ability to set redirects with .htaccess, and your site uses PHP, Chandrika's method would be adequate, although I would suggest two changes to the code:
PHP Code:
<?php
header
('Location: http://www.newurl.com',301);
exit();
?>
This should use lower overhead, and be more resistant to errors. By default, using header('Location') uses a 302 redirect, and some versions of PHP do not use the previously specified HTTP line correctly, so specifying the redirect code in the location line avoids this possible bug. Using the exit() function saves some processing by preventing any further code in the script from being processed, since it will not be visible to the user anyway.

If you have access to htaccess, I would strongly recommend using an explicit redirection:

Code:
# Change oldurl.com/oldpage.html to oldurl.com/newpage.html
Redirect 301 /oldpage.html http://oldurl.com/newpage.html
# Change oldurl.com/oldfolder/page.html to oldurl.com/newfolder/page.html
RedirectMatch 301 ^/oldfolder/(.*)$ http://oldurl.com/newfolder/$1
This method requires the least processing, and will work with any type of file, including images.
__________________
The best way to learn anything, is to question everything.
Reply With Quote