Friday, July 13, 2007

Implementing 301 Redirect Properly

What is 301 redirect?

A 301 redirect is a command used to tell the search engines that a page has permanently moved, and that you want them to index the new page and drop the old one from their index. It’s basically a change of address card for the Web. As long as everything is done correctly, a 301 redirect will ensure that you keep the rankings earned by the old page and it will prevent the duplicate content nightmare that should arise if the engines were to index box version of your site.

How to Implement 301 Redirects Using .htaccess for Apache?

Before you get yourself all excited about the fun you’re about to have, make sure you have access to your server, your Apache Configuration file, and that you can use your .htaccess files. The ability to use .htaccess files will reside in a command called "Allow Override" in the Apache Configuration file. If you do not have this access, you’ll have to first call your hosting company and get access.

Once you know that you have access to this file, your next step is to locate it. The .htaccess file is a control file that allows server configuration changes on a per-directory basis. It controls that directory and all of the sub-directories contained within. In most cases, this file will be placed in the root Web folder for your Web site. If there’s no .htaccess file present, create one.
To begin using the .htaccess file to redirect page(s) on your Web site, open up your FTP and login to your Web site. Work your way into in the root Web folder in order to access your .htaccess file. This little gem is the file you’ll need to edit. (A little piece of advice: The dot in .htaccess makes it a hidden file, so make sure your FTP browser is enabled to view hidden files. Otherwise you’ll never find it and your IT guy will laugh at you when you ask him for help.)

When you start editing the file, use a UNIX style text editor, not Notepad. Typically, an HTML editor or code editor such as TextPad works just fine. To 301 redirect pages using the .htaccess file, you will add a line to the file that will tell the server what to do. You can do this a couple of ways:

RedirectPermanent /old-file.html http://www.domain.com/new-file.html
-or-
Redirect 301 /old-file.html http://www.domain.com/new-file.html

A redirection from one domain to another would be:

RedirectPermanent / http://www.new-domain.com/

Our IT department reminds me there are some key things worth mentioning here:
  • The first section of the command tells the server what to do: RedirectPermanent or Redirect 301. Again, these commands are equivalent.
  • The second is the relative path to the file that you want to redirect. This must be the relative path to the location of the .htaccess file (i.e. /old-file.html).
  • The last section is the full path to the new file. This is a fully-qualified URL, meaning you need the http:// (http://www.domain.com/new-file.html).

Once you have inserted the commands to 301 redirect your pages, you need to make sure that there is a blank line at the end of the file. Your server will read the .htaccess file line by line, which means at some point you’ll need to throw them an “endline” character to let them know you’re finished. An easy way to do this is to put a blank line at the bottom of the file.
You can test that your redirect was done properly by heading over to your search bar, typing in your old domain name, and hitting search. If you’ve correctly implemented your 301 you’ll be immediately taken to the new location. If you haven’t, go play in traffic. You’re useless and should be ashamed of yourself. Zing!

How to do a 301 redirect using a Windows server?

Okay, this is a bit trickier. First, navigate your way to the Internet Services Manager (Programs -- Administrative Tools -- Internet Services Manager). Once you’re there, select the site you’re redirecting from, and right click to open up the properties menu. This will open up the Context menu. (Sadly, there is no ‘viola’ once this happens.)

Inside the Context menu you’ll see the “Home Directory” tab, click on it and select "A redirection to a URL" from the radio buttons at the top. The default choice will be to select “A directory located on this computer” but that is NOT the option you want. Once you’ve made your selection, type in the new URL you want your old domain to point to. Make sure that the “A permanent redirection for this resource" is selected in the checkboxes underneath.

The other checkboxes listed handle some different options, depending on what you want to do:

  • "The exact URL entered above": This will redirect the search spiders and users to the exact URL you entered in the "Redirect To:" box. For instance, if you somebody went to http://www.youroldsite.com/products/index.html, they would go to http://www.yournewsite.com/.
  • "A directory below this one": Freaky Friday images aside, this redirects a parent directory to a child directory. For instance, if someone typed in http://www.yoursite.com to access the site and you wanted the request to be redirected to a child directory named "tools", then they would be sent to http://www.yoursite.com/tools.

If you need more options for what you’re redirecting to, you can add some control variables to the “Redirect to” box where you just entered in the new URL. The most useful variable for domain redirects is $V. This removes the server name from the original request.

For example, http://www.youroldsite/directory1/page1.html would redirect to http://www.yourNEWsite.com/directory1/page1.html. Leaving this control variable out will only redirect the home page. If other pages are ranked in your site, then it would be extremely helpful to redirect those pages using these variables also.

If you don’t have access to your .htaccess file or your Windows Server Administration Panel, you can still implement 301 redirects with code on your old pages, but you have to do with one hand tied behind your back and wearing an eye patch. Fine, no eye patch. If your pages are in PHP, ASP, Java, or any other language that allows you to modify Response Headers, simply place code at the top of each page to do the Permanent Redirect.

Does 301 Redirect HURT Rankings ?

Aaron Wall posted a case study on a recent site move. He documented the traffic to the site, before, during and after the big move. He also documented how long Google, Yahoo, and Microsoft picked up the site on the new domain.

No comments:

The Blogosphere

Loading...
website stats