Use 301 Re-Directs
If you have read the earlier posts on this blog you will recall that I described using a 301 redirect to overcome a hacker’s attempt to steal my content and page-rank in the post called Site Hijacking (part 2). That technique worked smashingly, as I got any traffic that went to his site (and still do) and now the offending site is entirely removed from the search engine results.
Today, I’m going to talk about the more typical use for a 301 redirect, when you actually have moved content. There are many reasons to do this. I have one site that began in 1993 — before you could even have commercial content on websites (I didn’t actually have my own website, but controlled a directory within a larger site). Sometimes I find it best to move some of the content on that legacy site to one of my newer websites.
I certainly don’t want to lose any visitors though, and there are links all over the place to that content, so I use a 301 redirect to ensure that both search engines and visitors go to the new location. The procedure is simple.
First, I put the content on the new site. I keep the same filename and title and most of the content remains unchanged, though the layout is usually different on the new site.
Next, I replace the old page with a PHP header similar to that from my earlier post:
<?php header("Location:http://www.newsite.com/page.htm",TRUE,301); ?>
Of course I have a statement in the .htaccess file that ensures PHP gets parsed, since these old files were usually plain HTML:
AddType application/x-httpd-php .php .htm
If I used .html I could add that to the above line as well, but I’m lazy and never type an extra character I can avoid — all my HTML files end in .htm
Next, I remove all the links to that page from my sites. Some I point to the new location, others I point to other web pages in my Web Empire that need more traffic. I use the link:url search in Google and the SEOquake link to a similar feature in Yahoo (they keep changing the syntax, it is easier to search through this tool, which is updated frequently, than search Yahoo for the correct search syntax), to make sure I get all the links on my empire. If I recognize any of the links from outside my Web Empire as old friends, I’ll drop them an email to change their links. Similar emails to strangers are just deleted as spam and not worth the time and effort to write.
If the page or pages get much traffic, I sometimes add a ‘referer recorder’ to the original page, before the redirect. (Yes, referer is mis-spelled, ‘taint my fault — look it up if you don’t know why). That is a simple MySQL database table, with two fields, a counter and a text field for the referer. Since I am only interested in where visitors are coming from, and not the frequency for particular referers, I make the referer field a unique key. Then before the redirect I add this snippet of PHP code:
<?php
error_reporting(0);
include(open_db($db));
$serv=$_SERVER['HTTP_REFERER'];
$sql="insert into refer values('','$serv');
if($serv){mysql_query($sql);}
?>
I don’t want users to see any error messages, so I set reporting to zero. The include file is of course my open database code. $serv returns the referer (if any) and the subsequent code saves it (there is no need to specify the counter value as it is set to auto-increment).
After a month or two I check that table to see if any of the incoming visitors who are being redirected come from within my Web Empire — if so, I change the link. I’ll empty the table and check again in a few more months. When (and if) the table remains empty for months on end, I know it is now safe to remove the original page redirects and this table.
No Comments
You must be logged in to post a comment.