How to use 301 Redirect for moved or missing pages

What is 301 redirect?

301 redirect is a method of redirecting pages on your website to other pages on your site or elsewhere.

Why would you need to redirect content?

It is a method to retain search engine rankings for a page. If a page has previously been ranked by search engines and you changed the file name during a major redesign, or moved some of the content to another website the ranking is lost if you just move the page. If instead you do a 301 redirection the old ranking will be passed on to the new page.
Another use is to redirect traffic for deleted content somewhere on your website so that the traffic is not lost. Sometimes you need to remove outdated content and since you are still receiving traffic for those pages you would like to keep those visits.

What means a 301 Redirection?

301 redirect means “moved permanently”. When a search engine accesses a file marked as “Moved Permanently” it will note the new address and consider the new location as the valid one, passing on the ranking for the new page.

How to do a 301 Redirection

Apache 301 Redirection
Look for the .htacces file on the root of your website’s directory.
If there isn’t one create it. On Windows you might have difficulties to create a file with an empty name and only the extension. But once the file created, for instance on the host operating system you can edit the file using notepad or wordpad.
The simplest method is to place the following line into your .htaccess file:
redirect 301 /old-directory/old.htm http://www.mywebsite.com/new.htm
Don’t add the whole address on the first part, (the www) as the server uses its root directory as the referral point and not the http address.
Copy paste the statement below and modify it to reflect your needed redirection.
Upload the file on the server or overwrite the old file if you use direct access.
Test the redirection.

What if you want to redirect all of your files to another address? Fortunately you don’t need to add a redirect for each of your files. You can use the Apache’s URL Rewriting Engine module, which can handle complex redirections using regular expressions.

Redirect for a Moved Website

A rule that will redirect ALL of the files on your web server to another address:
redirectMatch 301 ^(.*)$ http://www.domain.com

A rule that will redirect http://mywebsite.com to http://www.mywebsite.com for SEO purposes:
RewriteCond %{HTTP_HOST} ^mywebsite\.com
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R=permanent,L]

Redirect to a Different File Extension

A rule to redirect your .htm pages to .php pages:
RewriteBase /
RewriteRule (.*).htm$ /$1.php

Redirect an Entire Directory

Redirect An Entire Directory/Folder to a single page. You got rid of the old content and you want to keep your visitors and keep the ranking of your old pages.
RewriteBase /
RewriteRule ^old-directory/(.*) http://www.mywebsite.com/new-directory/ [R=301,L]

You moved content in another folder or on another webpage and you would like to redirect visitors to exactly the same page at the new address.
Another use of this, is if your test site got indexed by search engines and is ranking better or the same as the regular website. It happened to me… Somehow my robots file got overwriten
RewriteBase /
RewriteRule ^old-directory/(.*) http://www.mywebsite.com/new-directory/$1 [R=301,L]

Redirection Troubleshooting

Make sure that you leave a single space between the different elements of the statement.
Make sure you have “RewriteEngine on” on your .htaccess file, without it your rules will not function.
Regex Tip:
The content between the round brackets is kept in memory and called when needed with the syntax $1 for the content of the first bracket, $2 for the content of the second bracket, etc.

What if I don’t have an Apache server? I use IIS.
The alternative for IIS is ISAPI_Rewrite for IIS. ISAPI_Rewrite gives you all the nice features that you have with Mod_Rewrite.

More on the Rewriting Engine module and the regex here:
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

Loading Facebook Comments ...

2 thoughts on “How to use 301 Redirect for moved or missing pages”

  1. found your site on del.icio.us today and really liked it.. i bookmarked it and will be back to check it out some more later

  2. This is great information, thanks. Do you know how to do the same within IIS? Specifically I mean for deleted pages, there does not seem to be much information on a Google search, “301 redirecting deleted pages on IIS”, so if you could port that information you would get traffic.

Leave a Comment

*