Sunday, April 24, 2011

Search engine friendly re-direct with php headers

Many times we need to re-direct a page to another page, due to lots of reasons like:
  1. You changed your URL patterns to new patterns.
  2. The Old links are dead.
  3. You simply moved your site to new domain,
And might be lots of other issues... But have you ever thought will search engine follow these links...
Here are simple PHP headers to re-direct the page to new location.

<?php
Header( "HTTP/1.1 301 Moved Permanently" ); 
Header( "Location: http://www.newurl-to-forward.com" ); 
?>
And alternatively if you want to manage re-direct in .htaccess file then you can do the following steps 

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^old_domain.com [nc]
rewriterule ^(.*)$ http://www.new_domain.com/$1 [r=301,nc]  

Thanks.
 

No comments:

Post a Comment