Domain redirecting using PHP, redirect whole site not just a pageFiled Under: php Programming, Tips and tricks
If your site is moved to a new domain with the same file structure as before you can use this code to redirect to the new location. Works well for content management systems like wordpress even without .htaccess
<?php
$url=$_SERVER['REQUEST_URI'];
$url=substr($url, 0, -1);
$url_new=”http://newdomain.com$url/”;
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: $url_new”);
exit();
?>
Place the above code before outputting html (Even before <html>).
What silly thing does this do ?
It does silly thing of concatenating the file name part in old domain to new domain and redirect the visitors and search engines. Since its server side redirect its search engine friendly and you won’t lose search engine juice.
- Read More
- The Analyst
- 20 Feb 2009 9:55 AM
- Comments (1)