There are many reasons why you may want to redirect a domain to another domain.
So, whether you are redirecting your domain to another because of traffic or whatever other reasons, the PHP header-redirect 301(permanently moved) still remains the best method!
The PHP header-redirect 301 tells the visitors and search engines alike that domain A has been permanently moved to domain B, and thereby redirecting all domain A visitors to domain B. When a domain is redirected to another, most search engine qualities of the first domain will be allocated to the second domain, example is Google Pagerank.
A simple PHP header-redirect 301 script:
header("location:http//domainb.com", 301);
exit;
?>
The above code, once placed in the index file of domain A, will redirect all visitors to domain B with a 301-permanently-moved note.
To get advanced we would like to redirect all the URLs in domain A to their perfect matches in the new domain B since the above code redirects all domain A URLs to exactly domainb.com. We will learn how to redirect URLs like http://domaina.com/kings/prince?q=arthur
to it's perfect match in domain B
http://domaina.com/kings/prince?q=arthur.
$uri=($_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
str_replace('domaina.com', 'domainb.com', $uri);
header("location:".$uri, 301);
exit;
?>
The above code will just replace domain A with domain B as the target URL and forward the visitor to the new URL.
Please feel free to ask any questions.




0 comments:
Post a Comment