Permanent Redirection with HTTP 301 using PHP

When you change your existing website on a new domain, you would be thinking to redirect all pages with their respective pages on a new domain.

For example, you would be needing. =>

When someone opens, they should be automatically redirect to This thing has 2 benefits.

1. Search engines like Google easily find that your website has moved to a new domain.
2. It is convenient for visitors to read the same content if they have bookmarked your old website url.

Furthermore, if you have more than one domains for a same website (most probably for the corporate websites, you might have booked all famous extensions such as .com, .net, .org, etc)

$httphost = $_SERVER[‘HTTP_HOST’];
$scriptname= $_SERVER[‘REQUEST_URI’];
$tourl = “” . $scriptname;
if($httphost != “” && $httphost != “”)
header(“HTTP/1.1 301 Moved Permanently”);
┬áheader(“location: ” . $tourl, true);

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks

Leave a Reply

Your email address will not be published. Required fields are marked *