301 Redirection - Part Two - Using .htaccess and mod_rewrite

December 6, 2006 – 2:11 pm

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

In this post we look at how to implement a Permanent (301 Status) Redirection using .htaccess. This assumes you have an Apache configuration.

If you’re fortunate enough to have an Apache web server, then you also have a module called mod_rewrite which has made life easier for web developers and SEOs. (IIS offers several addons to accomplish the same thing, but I have no familiarity with them.) This article is Part Two in an extensive series about 301 redirection.

First, decide which version of your domain you want to use universally. Do you want your website called domain.com or www.domain.com? Most people will choose to rewrite the non-www requests to the www requests, so we’ll use this in our example.

Add the following to your .htaccess file to forward all from the non-www version of your website to the www version. This is a permanent redirection.

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.net [NC]
RewriteRule (.*) http://www.yourdomain.net/$1 [R=301,L]

Some warnings about .htaccess

Make sure to keep a backup of your .htaccess file! If you make a typo, your whole website WILL stop working so make the backup in case you have to revert to the old version. This happens often enough I felt the need to warn you.

How can you test the configuration?

Testing the configuration is easy. Type your domain in without the www and when you get to the website in your browser you should notice the re-written URL clearly in your address bar. It’s as simple as that. If there’s no error messages on your screen, you’re done.

Enter the URL in the Server Header Checker and make sure it responds with:

Your Server Said:
HTTP/1.1 301 Moved Permanently

If you get this message, you have successfully forwarded all of your traffic using a Permanent 301 Redirection. It may take a few months for the search engines to visit all of your pages and rewrite all of your links, but you don’t have to worry once you set it. Just set it and forget it and the improvements to your rankings should be self-evident.

If you enjoyed this post, subscribe to the Sootle RSS feed!.

  1. 5 Responses to “301 Redirection - Part Two - Using .htaccess and mod_rewrite”

  2. I’ve never understood why search engines can’t realize that domain.com and http://www.domain.com are the same thing - why should every site owner have to junp through hoops to point out the obvious?

    By Chris on Dec 11, 2006

  3. Chris,

    The main reason is because they can be different. There are websites where there’s entirely different content on both domains.

    But for the most part, they could probably ASSUME that almost all webmasters will have the content the same.

    By Darren McLaughlin on Dec 13, 2006

  1. 3 Trackback(s)

  2. Dec 11, 2006: 301 Redirection How-To - Part One - Why It Matters In Google
  3. Dec 18, 2006: Some SEO Posts Of Note
  4. Feb 2, 2007: 2007 Google Dropped Website Checklist

Post a Comment