301 Redirection

A few caveats about 301 redirection. 301 Redirects are the best way to tell search engines that an old page you had moved to a new location. When 301 redirection is used properly, it's a deadly weapon. We take a look at some of the uses of 301 Redirects. The simplest 301 Redirect involves moving all of the content on one domain to another. Using Mod_Rewrite, this is a snap.
RewriteEngine On
RewriteRule (.*) http://www.yournewdomain.com/location/$1 [R=301,L]
Those two simple lines will help you move all of your website visitors to a new location. If you previously had pages at location.yourdomain.com and wanted to move them to www.yourdomain.com/location, then that one RewriteRule is all you need. Let's say you're concerned about the old www versus non-www conundrum. Again, a few simple lines added to your .htaccess file will help immensely.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.web-mastery\.net [NC]
RewriteRule (.*) http://www.web-mastery.net/$1 [R=301,L]
This rule makes it so that all requests for the non-www address are automatically (and permanently) forwarded to the www address. Doing this at the time you first set up a website will help save you some serious troubles later on as Google tries to decipher what address you want the domain referred to. If you implicity rewrite all requests, the Big G just can't get it wrong. If you don't have Mod_Rewrite, you can still generally redirect files by specifying the 301 redirect command directly in you .htaccess file.
Redirect 301 ^oldpage.htm http://www.newdomain.com/oldpage.htm
Now, these examples are all quite easy, but what if things get a bit tougher? Let's say you are getting rid of all your old pages, but you still want to conserve any backlinks to the pages, and any traffic you might get. You can set up a 301 redirection catchall. But you'll need to make note of several new caveats. First, you probably think that you can just redirect the traffic all to a new page, but you can't. The redirection attempts to send the request along to the fully qualified URL. If the users lands on yourolddomain.com/oldpage.html they will be redirected to yournewdomain/oldpage.html. If oldpage.html is not there, they'll get a 404 error. One way you can handle this is by stripping the request URI before sending them along. I suggest using PHP for this.
$req = $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] = "http://www.web-mastery.net/";
$nreq = $_SERVER['REQUEST_URI'];
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.web-mastery.net" );
You just grab the Request_URI and strip it before doing the redirection. You can call this file red.php and place it in your main directory. Now, for the finishing touch, make red.php your default 404 document by adding this line to .htaccess.
ErrorDocument 404 /red.php
Now, ALL requests for any pages will be redirected to the home page. Of course this may be disconcerting to the users, but at least you'll still get visitors and your backlinks will be redirected. You don't have to use the home page, obviously, either. You can redirect to whatever page you want. This is probably not the best solution in most cases, but in the event you lose a database or decide to wipe out a section of your website, it has proven very reliable for me in conserving rankings. The 301 is a tool you'll use more as you have more pages under your management. Learn it and live it.

Page generated: 0.012

Top post in webmaster-news
Being A Webmaster Means Change
Being a webmaster is about a lot of things, but none more important that being willing to accept change. If your website isn't ...
...viewed 1532 times

Copyright, 2002-2012, Web Mastery