htaccess File – 301 Redirect For SEO

by Frank Pipolo on May 7, 2009

in SEO

Why use a 301 redirect in your htaccess File? Moving your pages is the worst thing you can do for SEO. When you do you lose your link juice, lose bookmarks, and you give the SE’s an error page and too many of those can give the SE’s the impression of less authority.

Changing any aspect of your page’s URL will result in broken links, broken bookmarks, and de-indexed pages—not to mention lost traffic and revenues for your site. That includes changing any of the following…

  • Changing a web page file name, such as flower.html to flowers.html.
  • Changing a web page file extension, such as .html to .php.
  • Changing a directory name, such as /directory/file.html to /directory2/file.html.
  • Modifying (or leaving off) URL variables that are necessary to retrieve a page, such as http://www.domain.com/index.asp?id=45 (where id=45 is a necessary variable).
  • Changing a subdomain name, such as www.domain.com/phpbb to forum.domain.com.

Bottom line – a small change is a big deal period!

What’s a 301 Redirect for SEO?

Whenever your web server “serves” up one of your web pages to a visitor (be they human or search engine) it also serves up a status code. This status code tells the visitor the state of the page and is composed of a three-digit number and a short description.

For instance, 200 OK says the web page was downloaded successfully, while a 404 Not Found status code indicates that the page could not be found. W3.org has a complete list of Server Status Code Definitions.

The 301 redirect is served up as 301 Moved Permanently and says the page has been permanently moved to a new location. It also returns the URL address of that new location.

Search engine spiders are then instructed to update their records for that page. This means that the page will stay in the search engine’s index and that PageRank and incoming links for that page should be transferred to its new location.

Without the 301 redirect, the search engine receives a 404 Not Found error and the page is dropped from the search engine’s index. All PageRank and incoming link equity for that page also disappears.

When to Use a 301 Redirect

Besides simply moving a page from one location on your site to another, 301 redirects have a number of important uses, including:

  • Moving your site to a new domain name.
  • Cleaning up ugly dynamic URLs so that search engines can crawl them more easily (combined with a URL rewriting tool).
  • Closing pages or entire sections of your site and making sure both your users and search engines don’t run into link “dead-ends.”
  • Pointing your extra domain names or outdated sites at a single location to consolidate traffic and links.
  • Prevent duplicate content problems when both the www and non-www version of your site are accessible.
  • Prevent duplicate content problems when both the directory root (/) and index.html versions of a page are accessible.

The Best Approach for Apache Users: The .htaccess File

Most web sites are run on one of two different kinds of servers…

  • Unix-based servers running Apache.
  • Microsoft Windows-based servers running IIS or similar.

If you’re unsure of what kind of server runs your site, ask your web host. Most sites (including this one) are run on Unix-based servers with Apache. In that case, the server’s behavior is configured using something called the .htaccess file.

What’s a .htaccess File?

A .htaccess (pronounced “dot-H-T-access”) file is a simple text file that resides in the root directory of your web site where, typically, your home page also resides. The .htaccess file serves a variety of different functions and can live in other directories as well but, for the purpose of doing a 301 redirect, you should place a .htaccess file in your root directory. If one doesn’t already exist, you can create it using any plain-text editor (like NotePad, or TextPad – do not use MS Word), then name the file .htaccess (that’s right, no extension – just a period followed by htaccess).

If your site’s root domain already contains a .htaccess file, you can simply scroll to the end of whatever code is already there and append your 301 redirect code at the bottom of the file, starting on a new line. While this may sound complicated, it’s actually very, very simple to do. If you can upload files to and from your web server, then chances are you’ll have no trouble managing (i.e. altering or creating and uploading) your .htaccess file(s).

Any time you need to move pages or change any aspect of your site’s URLs, you do so by placing specific instructions in your .htaccess file. These allow your server to send (or redirect) users and search engines to the page’s new location.

How to Move Pages on the Apache Server

The simplest example of redirection would be renaming a page in your root directory. For example, changing a page’s URL from…

http://www.domain.com/old-page.html

to…

http://www.domain.com/new-page.html

Just add code similar to the following to your .htaccess file…

Redirect 301 /old-page.html http://www.domain.com/new-page.html

  • Redirect 301 – This tells search engines (and browsers) that your page has been moved permanently.
  • /old-page.html – This gives the old location of the page. Note that you leave off the http://www.domain.com part of the page’s URL.
  • http://www.domain.com/new-page.html – This is the new location of the page. From now on, search engines should always look here for the page. Note that this part requires the complete URL.

Now if you have multiple page you have moved the SE’s want you to make a single entry for each page like this:

Redirect 301 /old-directory/old-page1.html http://www.domain.com/new-directory/new-page1.html
Redirect 301 /old-directory/old-page2.html http://www.domain.com/new-directory/new-page2.html
Redirect 301 /old-directory/old-page3.html http://www.domain.com/new-directory/new-page3.html

Now if you need to move many pages within a directory you can use the follow code but be aware that it works well but is not best practice.

Redirect 301 /old-directory/ http://www.domain.com/new-directory/

Now, you may have an outdated page that you want to shut down, but you want to make sure that your site still gets credit for the links pointing at that page, and that anyone who might try to access that page in the future doesn’t get a 404 (page not found) error then use code like this:

Redirect 301 /old-page.html http://www.domain.com/

Moving a page to a new location is a fairly painless process. By providing a clear path to the page’s new location, you ensure that both your users and the search engines find what they are looking for—while you avoid losing your existing search rankings and/or inbound links.

Next post I will go over some advanced uses for a 301 redirect.

{ 1 comment… read it below or add one }

marco May 8, 2009 at 6:30 pm

Thanks Frank, I was just now in need of this article… I just redesigned my site and some pages from the old site were in limbo… Thanks to your article now they are being redirected to the new pages…

Leave a Comment