Get Free Quote

BACK TO BASICS: Methods and Implementation of Redirects

by Virginia Nussey, June 30, 2008

Web developers have a number of choices when implementing a redirect. Depending on the type of server, the scale of the project and the reason for the redirect, programmers can choose from several options to redirect individual URLs or entire domains. Some methods have greater search engine optimization benefits than others. In this article, we will outline those options and provide the steps of implementation for preferred methods.

Types of Redirects

The 301 redirect is the preferred and most SEO-friendly form of redirect. Also known as a permanent redirect, the 301 informs a search engine that the page has been permanently moved to a new location. In turn, the search engine will drop the now defunct page from the index, include the new page in the index, and transfer rankings and link popularity from the old page to the new. The 301 redirect is also the SEO-preferred form of redirect because it eliminates the possibility of creating duplicate content within the search engine index. Because a search engine responds to a 301 by dropping the old page, the chance of having two pages in the index with the same content is avoided.

A common redirect is the 302, or temporary, redirect. This type is not as beneficial for SEO purposes as it is known to cause duplicate content to be indexed, which can then cause pages to be filtered from SERPs or be assigned to a supplemental index. Duplicate content can be caused by a 302 redirect because the command tells the search engine that a page has been temporarily moved and the search engine responds by retaining the original page in the index and attributing the content on the new page to the original page. If a search engine then arrives at the new page through an alternate route it will index the page and, voila, there is duplicate content. There are many good reasons for implementing a 302 redirect, but unless the new page is truly required only temporarily, it is not a recommended practice.

A JavaScript redirect is also not recommended from an SEO perspective. The benefit of a JavaScript redirect is the ability to redirect based on settings that can be detected by JavaScript, such as browser type, if the user has Flash capabilities, if the user accepts cookies, etc. The problem is that search engines don't execute JavaScript and therefore cannot follow the redirect. In such cases, a search engine will flag instances of JavaScript redirect for human review. Sites are then dependent on the discretion of the human reviewer who determines if the redirect benefits the user - in which case it will usually be allowed - or is a tactic for delivering a different page to a spider than a user - in which case it may be penalized. The policy at Bruce Clay, Inc. is to never implement JavaScript redirects, even if only temporarily.

A Meta refresh is a way of telling a Web browser to automatically refresh a Web page after a given time interval. The refresh can also be used to fetch another URL, so when the refresh time interval is set to zero or one second the Meta refresh serves as a method of URL redirection. Because Meta refresh can be used to show different content to a search engine than a user, using a Meta refresh for a redirect is discouraged by search engines and the W3C. In fact, some search engines see Meta refresh redirects as a prompt for a spam flag.

Implementing a 301 Redirect

As you can see, there are a number of types redirects and many ways to implement each; however, the 301 redirect is the most recommended and search-engine-friendly method.

Because search engines, the W3C and we at Bruce Clay, Inc. all believe that the 301 redirect is the preferred method, the following instructions will demonstrate the way to program a 301 redirect for both Apache and IIS servers.

With access to your Apache or IIS server, implementing a 301 redirect is a worthwhile way of ensuring link popularity transfers and inbound links, search engines and interested users can locate your new URL.

Apache Servers

To implement a 301 redirect on an Apache server, you need to have access to your server and your Apache Configuration file. If you do not have access to your server you can call your hosting company to get access. Using a command called "Allow Override" in the Apache Configuration file allows the override of .htaccess files. The .htaccess file is a control file that allows the programmer to customize configuration for individual directories and all sub-directories contained within. Once you have allowed .htaccess override, open the .htaccess file located in the root directory of the Web server. If there is no .htaccess file, create one.

To edit the .htaccess file, use a UNIX style text editor, such as an HTML editor or code editor such as TextPad. To redirect pages, add a line to the file telling the server what to do. This can be done several ways.

  • Example 1 - from URL to URL:
    RedirectPermanent /old-file.html
  • Example 2 - from URL to URL:
    Redirect 301 /old-file.html
  • Example 3 - from Domain to Domain:
    RedirectPermanent /

There are three parts to the directive, which should all be on one line. The first is the redirect command. The second is the root relative path to the file or directory that is being redirected; for example, /old-file.html refers to The last part of the line is the full URL of the page being redirected to. Each part is separated by a single space. Each directive should be followed by an empty line.

If you are confused by the second and third examples above, that is because both include exceptions to the rules. In the second example, the "Redirect" command by itself will accept the type of redirect after it; in this case it is a 301 redirect, and "Redirect 301" is read as the first part of the directive. In example number three above, the second part of the directive is a lone slash. This instruction is understood as the entire directory and all sub-directories.

After you have added your redirect directive to the .htaccess file, test to see if it has been properly implemented by typing the URL of the redirecting page or directory into your browser. If the URL redirects to the proper page, the redirect has been correctly executed.

IIS 7.0 Server Redirects

To implement a 301 redirect on a Microsoft IIS 7.0 server, you will need access to the IIS Manager. For this method you must also download the URL rewrite module, available in both 32-bit and 64-bit versions. Go to the IIS Manager (Start > Programs > Administrative Tools > Internet Information Services Manager) and select the site that will be redirected. Then, go to the Feature View and click "URL Rewrite Module". In the "Actions" menu on the right-hand side of the page, select "Add Rule". An "Edit Rule" page will open, and here you will add the redirect rewrite rule. In the URL Rewrite Module, every rule requires four pieces of information:

  1. Name of the rule
  2. Pattern to use for matching the URL string
  3. Optional set of conditions
  4. Action to perform if a pattern is matched and all conditions checks are accepted

In the following example, the redirect rewrite rule created will redirect http://domain/blog/2007/archives to http://domain/article/archives/2007.

On the "Edit Rule" page, enter the following information in the stated fields:

Field Info to Enter Notes
Name Redirect from blog The name you enter will be unique for each rule.
Pattern ^blog/([_0-9a-z-]+)/(/[0-9]+) This pattern will match the URL string starting with "blog" along with the second and third segments that follow.
Action Redirect This action will send a redirect response to the browser.
Redirect URL article/{R:2}/{R:1} This substitution string is the new redirect URL; using back-references, the original URL pieces captured during pattern match are preserved and rearranged.
Redirect type Permanent Select this type from the drop-down menu.

It is worth noting that "Append query string" will be checked by default. If you do not want any query strings appended to the new URL, uncheck the box.

Leave all other settings at their default values and save the rule by clicking "Apply" on the right-hand side. Then test that the redirect has been correctly applied by typing the URL intended for redirection into a browser. The browser should automatically be redirected to the newly-created URL.

This is the recommended method of implementing a 301 redirect within a Microsoft IIS 7.0 server. For a tutorial of redirection with Microsft IIS 5.0 and 6.0, please see the previously published article and blog post on the subject.

For permission to reprint or reuse any materials, please contact us. To learn more about our authors, please visit the Bruce Clay Authors page. Copyright 2008 Bruce Clay, Inc.