Basic 301 Permanent Redirect

Major search engines are cracking down on websites that use sneaky redirects or point multiple domains to the same content without using a proper redirect. The 301 permanent redirect is known to be a search engine friendly redirect when needed.

Creating a 301 Permanent redirect with the htaccess file requires that your website is hosted on an Apache (Linux, Unix) based server. If you are unsure, a simple header check will indicate your server type. If you are not certain you understand the server information provided from the header check, please contact your web host for assistance.

The following basic 301 permanent redirect tutorial will walk you step by step, through the basics of setting up your first .htaccess file and adding the proper coding for the redirect.

Creating the .htaccess File

- Right click on an empty area of your desktop
- Select: New > Text Document

See Screen Shot

- Open the new text document
- From the menu, select: File > Save As

See Screen Shot

A box will open. At the top of the box make sure it says Desktop next to the Save in area.

- To the right of File name type in .htaccess
- To the right of Save as type, select All Files
- Click the save button.

See Screenshot

You should now see a new file on your desktop that does not display a file name with it.

Adding 301 Permanent Redirect Code

If you want to redirect all pages of an entire site to the main page of another domain, add the following code to the file, on a single line.

RedirectMatch 301 (.*) http://www.yournewdomain.com/

Make sure to save the changes to the file. The .htaccess file would now be uploaded to the same location where you uploaded the index page to your OLD domain that you are redirecting from.

If you want to redirect one page to another page, add the following code to the file, on a single line.

redirect 301 /old-file-name.htm http://www.gnc-web-creations.com/new-file-name.htm

Make sure to save the changes to the file. The .htaccess file would now be uploaded to the same location where you uploaded index page to your site. If the old page is within a different directory (folder) as your index page, then you would need to adjust the path of the old file name accordingly.

For example, if the old file name is located within a directory named category, your code would be as follows:

redirect 301 /category/old-file-name.htm http://www.gnc-web-creations.com/new-file-name.htm

If the old page is within a different directory (folder) as your index page, and you also want the new page within that same directory, then you would need to adjust the path of the old and new file name accordingly.

For example, if the old file name is located within a directory named category, and the new page will be also, your code would be as follows:

redirect 301 /category/old-file-name.htm http://www.gnc-web-creations.com/category/new-file-name.htm

Again, make sure you save changes to the file and upload to the same location where you uploaded the index page of the old location.

Enter your domain and file name info into the above codes!

This is an extremely basic tutorial for creating a .htaccess file to add a very simple 301 permanent redirect for a page or site. For advanced tutorials and codes, consider the following articles:

- 301 Permanent Redirect by Brian V. Bonini
- Apache HTTP Server Apache Module

Once you have completed uploading your new .htaccess file, it is imperative to that you verify everything is working correctly.

Try the old URL and confirm that you are being redirected to the correct page. You also need to verify that your server is returning the proper information (301 Permanent) for this redirect by doing a header check of the old page or domain.

Update: March 19, 2006

There have been a ton of questions about the with and without www linking issue. Once you have selected which you are using, then you would add a 301 permanent redirect for the other.

I recommend sticking with the www unless you have already established not using it on your site.

To tell us which version you want the content indexed under, we recommend you do a 301 redirect from one version to the other. If your site runs on an Apache server, you can do this using an .htaccess file. You can also use a script. Inside Google

This should be done even when your server is set up to display your site either way. This prevents some of the (canonical) issues that happen when someone (including yourself) accidentally links using the opposite of what you use and are indexed as.

This is the code I use. I am sure there are others. This is simply what I use on a Linux (Apache) based server. Make sure to replace the generic domain information with your own.

To Redirect mysite.com to www.mysite.com

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]

To Redirect www.mysite.com to mysite.com

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

Once you have completed the change, VERIFY that everything is working properly and conduct a header check to verify a 301 is returned for the incorrect version.

If for any reason the above code doesn’t work, remove it from your htaccess file and request assistance from your web hosting company

I WILL DEFINITELY SEE YOU AT THE TOP!

J. Cricket Walker

Small Business Marketing Consultant and SEO Training Specialist
Copyright © 2007 J. Walker of GNC Web Creations All Rights Reserved