301 redirect tutorial

With the start of the new year come thoughts of doing some cleaning up of your website. Some of your file names have spaces in them like my page name.html. A Windows system will have no trouble with the file name either on the server or on your own computer. A UNIX operating systems (which run most servers) will have problems with them, and interprets the space as a "%20" character and looks for a file named:  my%20page%20name.html.

You go through and rename those pages on your site but what if Google has already indexed your site? What if that page already has a nice page rank? By changing  the file names, you run the risk of losing traffic and leaving visitors to your site who follow a search engine link with the dreaded "Error 404 - File not found." Creating a 301 permanent redirect is the best way to go.

N. B. If your site is hosted on a free server like RootsWeb or your ISP space, you are probably NOT going to have access to your .htaccess file to follow these instructions.

IMPORTANT! - If you want to redirect a non www domain to a www domain, you will need to follow the Google Canonical problems - www versus non.www tutorial.

What is 301 redirect?

Google says:

If you need to change the URL of a page as it is shown in search engine results, we recommended that you use a server-side 301 redirect. This is the best way to ensure that users and search engines are directed to the correct page. The 301 status code means that a page has permanently moved to a new location.

301 redirects are particularly useful in the following circumstances:

  • You've moved your site to a new domain, and you want to make the transition as seamless as possible.
    Example: I created a new domain for all of my Expression Web Tutorials and created a 301 redirect from the old domain to the new domain.
  • People access your site through several different URLs. If, for example, your home page can be reached in multiple ways - for instance, http://example.com/ or http://www.example.com - it's a good idea to pick one of those URLs as your preferred (canonical) destination, and use 301 redirects to send traffic from the other URLs to your preferred URL. Detailed Tutorial www versus non.www

Create and Implement 301 redirect for a single page

A 301 redirect is implemented in your .htaccess file. If you have FrontPage Server Extensions installed on your server do NOT follow these instructions. If you already have an .htaccess file on your server, you will need to download the file in the root directory of where all your web pages are stored. If there is no .htaccess file there, you can create one with Notepad. If there are lines of code that are already a part of your .htacess file,  be very careful not to change any existing line or lines. If you have FrontPage Server Extensions installed you will need to follow these instructions.

  1. Open Notepad or any plain text editor - do NOT use your word processor
  2. Save the file with the name .htaccess - note the dot in front and there is no file extension
  3. Type the following using a separate one for each page you are redirecting
    Redirect 301 "/directory/old file name.html" http://www.your-domain.com/directory/new-file-name.html making sure your are using your files names, directory name and domain name. N.B. Note the use of the quotes at the beginning and end of the old file. Mine did not work until I added these.
    Redirect 301 /old-file-name.htm http://www.your-domain.com/new-file-name.htm
  4. Upload the file to the root directory of your server with your ftp program making sure to select ASCII as the transfer type.
  5. Test the redirect by typing in the old address to the page you've changed. You should be immediately taken to the new location.

Do not add "http://www" to the first part of the statement - just put the path from the top level of your site to the page. Also ensure that you leave a single space between these elements:

redirect 301 (the instruction that the page has moved)

/old/old-file-name.htm (the original folder path and file name)

http://www.your-domain.com/new.htm  (new path and file name)

The next time the search engines spider your site, they will follow the rule you have created in your .htaccess file. During the next update, the old file name and path will be dropped and replaced with the new one. It will NOT happen overnight.

Additional Resources

Basic 301 Redirects

301 Permanent Redirect

Advanced Help With 301 Redirects

BlueHost 301 Redirects

Pat Geary.