301 Redirect with PHP

301 Redirect

301 Redirect

So I finally got my home server all patched up and doing my bidding while I am away but I cam across issues that I am still getting hits for really old pages that the computer used to host.

Since the page contained old data that I no longer have I decided that it would be a good idea to redirect to my current site…. well this site. I learned along the way that hosting your own site, though cheap, is a total pain in the butt and should only be done if you are running some high availability server or something. On a residential connection I was used to seeing my bandwidth peak from 4pm EST to 11pm EST all dependingĀ  on the day of the week and other variabes. So in short at times I was unable to use my connection because the upload bandwidth was saturated with connections making it a poor experience for myself as well as the visitors to my site.

So to get the the redirect, it is a simple enough piece of code that if inserted into the

index.php

file would redirect to my new site with a 301 Permanently Moved error, which would also preserve the page rankings but would do nothing about the backlinks. Fixing the backlinks is a whole other story that I will be working on at some point in the future.

So enough of my babbling on and here is the code.

<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?>

Just insert into the second header line the new URL that you will be using and save, everything that directs to the index page will now redirect to the new URL and everything is good…. well good enough for now at least.

Share and Enjoy:
  • Digg
  • del.icio.us
  • Technorati
  • MySpace
  • Reddit
  • Slashdot
  • StumbleUpon
  • Facebook
  • Google Bookmarks
  • NewsVine
  • TwitThis
  • RSS

0 Response to “301 Redirect with PHP”


  • No Comments

Leave a Reply