Get Free Quote

Sorting Out Redirects

by: Susan Esparza and Aaron Landerkin, April 2005

There are several different types of redirects in the world of the internet. All have different functions and some are more search engine friendly than others. The purpose of this article is to define and explain four common redirects: 301, 302, JavaScript and meta refresh. We will close with a look at the proper implementation of a 301 redirect.

301 redirect: 301 is a command that tells the search engines the page has permanently moved. The response is to index the new page and drop to old page. This is the right way to move a page. It will maintain the ranking of the page and prevent duplicate content in the engines. If you are moving domains, this is the redirect to use. 301 redirects are key to the proper implementation of an IP funnel as well.

302 redirect: 302 is a temporary move. The message to the search engines is that the new page is only a temporary home and not a valid address for indexing. The response is to keep the old page and attribute the content on the new page to the original address. 302 redirects have been the subject of a great deal of interest following the problem of a rise in hijacking pages by 302 redirects. A 302 hijacking can be devastating to a site, causing duplicate content penalties and loss of ranking. For SEO purposes, there is no reason to use a 302 redirect.

JavaScript: JavaScript redirects are useful for many reasons. The script is easy to implement and fairly versatile. It can pull from a cookie to serve up more personalized content or simply redirect to a new window. The object is to ensure that whatever content you pull can also be indexed by the search engine and is not deceptive.

Meta refresh: Meta refreshes are measured in seconds. Meta refresh is useful for sites that need to be updated on a timely basis. Brokerage sites may implement a meta refresh of 60 seconds to keep stock prices current. Redirects of zero or one second are considered 301 redirects by the search engines. Two seconds or greater will be considered as a 302. Meta refreshes are not substitutes for correctly applied 301 redirects. Both JavaScript and meta refreshes are commonly associated with spam and should be used with great care.

In actuality when moving a page, you should always use a 301. There isn't any good reason to move a page any other way if you want to preserve your web position. The way to do a 301 redirect depends on the type of server you have. Most Linux servers use Apache as the web server. Microsoft servers use IIS. We have included instructions on how to include a 301 on both types of servers.

How to do a 301 redirect using .htaccess for Apache.

Redirecting pages or sites with Apache is very easy, as long as you know how to use the .htaccess file.

The .htaccess file is a control file that allows server configuration changes on a per-directory basis. The file controls that directory and all of the sub-directories contained within. Most of the time, this file will be placed in the root web folder for your website.

Before you start, you should make sure that you can use .htaccess files. If you have access to your server and your Apache Configuration file, make sure that .htaccess files can be used. This will reside in a command called "Allow Override". If you do not have this access, call your ISP and ask.

To use the .htaccess file to redirect page(s) on your website, open up your FTP and login to your website. In the root web folder, there should be a file called .htaccess. NOTE: If there is not a .htaccess file present, you may create one.

Edit the .htaccess file using a UNIX style text editor, not Notepad. Usually, an HTML editor or code editor such as TextPad will do the job. To 301 redirect pages using the .htaccess file, you will add a line to the file that will tell the server what to do. There are a couple ways to do this and they all accomplish the same thing.

RedirectPermanent /old-file.html http://www.domain.com/new-file.html

-or-

Redirect 301 /old-file.html http://www.domain.com/new-file.html

A redirection from one domain to another would be:

RedirectPermanent / http://www.new-domain.com/

There are some important things to note here:

  1. The first section of the command tells the server what to do: RedirectPermanent or Redirect 301. Again, these commands are equivalent.


  2. The second is the relative path to the file that you want to redirect. This must be the relative path to the location of the .htaccess file. If you place the file in your root web directory, then you can use the URL of the file without the domain name, i.e. /old-file.html. There is no need for the http:// etc.


  3. The last section is the full path to the new file. This is a fully qualified URL, i.e. http://www.domain.com/new-file.html


How to do a 301 redirect using IIS 5.0 and 6.0.

If you are on a Microsoft server, 301s can be a bit more complicated. Start the Internet Services Manager. Select the Website you wish to redirect from; right click and select properties from the context menu.

Click on the "Home Directory" tab and select "A redirection to a URL" from the radio buttons at the top. The menu screen should look similar to the one above.

Type in the new site that this site will point to and make sure that "A permanent redirection for this resource" is selected. There are other checkboxes that handle some different options, depending on what you want to do: "The exact URL entered above" - This will redirect the user (or search engine bot) to the exact page as you entered in the "Redirect To:" box. For Example, if this was checked, and somebody went to http://www.youroldsite.com/products/index.html, they would go to http://www.yournewsite.com/.

"A directory below this one" - this option will redirect a parent directory to a child directory. If someone were to type in http://www.yoursite.com to access the site and you wanted the request to be redirected to a child directory named "apps", then they would be sent to http://www.yoursite.com/apps. To set this option, type in the name of the subdirectory in the URL textbox. "A permanent redirection for this resource" - This is to tell the browser that this is a 301 - Permanent Redirect. This will update bookmarks as well as search engine indexes of the old page.

There are also some control variables that you can pass to the "redirect to:" URL name to have more options of what you are redirecting.

Server Variable

Function

Example

$P

Passes parameters that were passed to the URL to the new URL.

If the request contains parameters such as http://www.yoursite.com/mypage.asp?Param1=1 then $P would represent all the values after the question mark in the URL, example $P would equal Param1=1.

$Q

Passes the parameters including the question mark.

This is the same as $P but includes the question mark. So $P would equal ?Param1=1

$S

Passes the matching suffix of the URL to the new URL.

If the request is for http://www.yoursite.com/mydir/mypage.asp, then $S represents /mypage.asp. If the request was for http://www.yoursite.com/mydir then the value of $S would be /mydir

$V

Removes the server name from the original request.

If the request is for http://www.yoursite.com/mydir/mypage.asp then $V would contain everything after the server name, ex: /mydir/mypage.asp.

*

Wildcard symbol used for replacement.

Say for instance you want to redirect all requests for html pages to a single asp page you could do so in the following way: *;*.htm;myasp.asp

For domain redirections, $V is the most useful. If the directory structures and page names are all the same, and only the domain has changed, then in the "redirect to:" text box, you would have something like "http://www.yournewsite.com$V". This will redirect all directories and page names from the old site to the new one as long as they are the same. For Example, http://www.youroldsite/directory1/page1.html would redirect to http://www.yourNEWsite.com/directory1/page1.html. Leaving this control variable out will only redirect the home page. If other pages are ranked in your site, then it would be extremely helpful to redirect those pages using these variables also.

To finish, press "apply" and "ok" and the redirection will be put into place. That's it!

Variables table from this article.