Redirection
Redirection is process of forwarding one URL to a different URL. There are three main kinds of redirects online; 301, 302 and meta refresh.Types of Redirects
- 301 ('Moved Permanently') - Recommended for SEO
- 302 ('Found' or 'Moved Temporarily')
- Meta Refresh
What is a Redirection?
A redirect is a way to send both users and search engines to a different URL than the one they originally requested. Below are descriptions of some of the commonly used types of redirects.
301 Moved Permanently
A 301 Redirect is a permanent redirect which passes between 90-99% of link juice (ranking power) to the redirected page. 301 refers to the HTTP status code for this type of redirect. In most instances, the 301 redirect is the best method for implementing redirects on a website.302 Found (HTTP 1.1) / Moved Temporarily (HTTP 1.0)
A 302 Redirect is a temporary redirect and passes 0% of link juice (ranking power) and in most cases should not be used. The Internet runs on a protocol called HyperText Transfer Protocol (HTTP) which dictates how URLs work. It has two major versions, 1.0 and 1.1. In the first version 302 referred to the status code 'Moved Temporarily'. This was changed in version 1.1 to mean 'Found'.307 Moved Temporarily (HTTP 1.1 Only)
A 307 Redirect is the HTTP 1.1 successor of the 302 redirect. While the major crawlers will treat it like a 302 in some cases, it is best to use a 301 for almost all cases. The exception to this is when content is really moved only temporarily (such as during maintenance) AND the server has already been identified by the search engines as 1.1 compatible. Since determining if the search engines have identified this essentially impossible, it is best to use a 302 redirect.Meta Refresh
Meta refreshes are a type of redirect that is executed on the page level rather than the server level (They are usually slower and not a recommended SEO technique). They are most commonly associated with a 5 second count down with text "If you are not redirected in 5 seconds, click here". Meta refreshes do pass some link juice but are not recommended as an SEO tactic due to usability and the loss of link juice passed.SEO Best Practice
It is common practice to redirect one URL to another. When doing this, it is critical to observe best practices in order to maintain SEO value.
The first common example of this takes place with a simple scenario, a URL that needs to redirect to another address permanently.
There are multiple options for doing this, but in general, a single one, the 301 redirect, is preferable for both users and search engines. Serving a 301 indicates to both browsers and search engine bots that the page has moved permanently. Search engines interpret this to mean that not only has the page changed location, but that the content, or an updated version of it, can be found at the new URL. The engines will carry any link weighting from the original page to the new URL, as below:
Be aware that when moving a page from one URL to another, the search engines will take some time to discover the 301, recognize it, and credit the new page with the rankings and trust of its predecessor. This process can be lengthier if the given web page if search engine spiders rarely visit it or if the new URL doesn't properly resolve.
Other options for redirection, like 302s and meta refreshes, are poor substitutes, as they generally will not pass the rankings and search engine value like a 301 redirect will. The only time these redirects are good alternatives is if a webmaster purposefully doesn't want to pass link juice from the old page to the new.
Transferring content becomes more complex when an entire site changes it's domain or when content moves from one domain to another. Due to abuse by spammers and suspicion by the search engines, 301s between domains sometimes require more time to be properly spidered and counted. For more on moving sites, see Danny Dover's SEO Guide: How to Properly Move Domains.
301 Redirects in Apache
Problem:
Back when seomoz.org was originally created, it was hosted at www.socengine.com/seo/ rather than on its own domain. When the original developers were moving seomoz.org to its own dedicated server, they wanted it to be accessed as its own domain rather than as a subdirectory of socengine.com. They needed visitors accessing anything in www.socengine.com/seo/ to be redirected to www.seomoz.org. The redirection had to accommodate several file and folder name changes and had to be done with 301 redirects in order to be search engine friendly. They also needed to forward http://seomoz.org to http://www.seomoz.org for aesthetic purposes and to avoid canonicalization errors.Solution:
The simplest approach to do this would have been to add 301 redirects to the PHP code that powers SEOmoz.org using PHP’s header function. Utilizing the power of the apache module mod_rewrite, however, the developers realized they could match specific patterns for entire folders and redirect them to their new URLs without having to go through every PHP script.Installation:
In order for this to work a web server needs to have the apache module mod_rewrite installed.Most apache installations will have mod_rewrite installed by default. SEOmoz's original server rand the Linux distribution FreeBSD and mod_rewrite was included by default. To check to see if the module is installed, a developer can verify it is working by adding the following line to the apache configuration file or or to an applicable .htaccess file:
RewriteEngine On
Context
The mod_rewrite module operates in per-server context or in per-directory context.The per-server context requires that a developer must edit the apache configuration file, httpd.conf. The per-directory context uses .htaccess files that exist in each folder a user wants to configure. If a webmaster can not access httpd.conf, they will have to use .htaccess files.
Regular Expressions (aka Regexes)
From wikipedia.org:Regular expressions are an valuable skill to learn for both programmers and systems administrators. To redirect URLs according to the examples in this document, it is important to understand the basics of using regexes. The following is a list of the characters and operators that are used in the regexes described in this document:A regular expression is a string that describes or matches a set of strings, according to certain syntax rules. Regular expressions are used by many text editors and utilities to search and manipulate bodies of text based on certain patterns.
- . Period - matches anything.
- * Asterick – matches zero or more of the preceding character
- + Plus sign – matches one or more of the preceding character
- ( ) Parenthesis - enclosing a value in parenthesis will store what was matched in a variable to be used later. This is also referred to as a back-reference.
- (value1|value2) - Enclosing two or more values in parenthesis and separating them with a pipe character is the equivalent of saying: “matching value1 OR value2.”
Redirecting specific files and folders from one domain to another:
The original developers at SEOmoz needed redirection from the old server to the new one with the filenames preserved.Example
Redirect: http://www.socengine.com/seo/somefile.php To: http://www.seomoz.org/somefile.phpSolution
Add the following directive to the applicable file on socengine.com's server:RedirectMatch 301 /seo/(.*) http://www.seomoz.org/$1
Explanation:
The regular expression/seo/(.*)
tells apache to match the seo folder followed by zero or more of any characters. Surrounding the .* in parenthesis tells apache to save the matched string as a back-reference. This back-reference is placed at the end of the URL that was directed to, in this case, $1.Redirecting Canonical Hostnames:
The original developers at SEOmoz needed to redirect any requests that do not start with www.seomoz.org to make sure they included the www. They did this not only because it looks better, but to avoid common canonicalization errors.Redirect: http://seomoz.org/
To: http://www.seomoz.org/
Redirect: http://mail.seomoz.org/
To: http://www.seomoz.org
Redirect: http://seomoz.org/somefile.php
To: http://www.seomoz.org/somefile.php
Solution:
Add the following directive:RewriteCond %{HTTP_HOST} ^seomoz\.org [NC]
RewriteRule (.*) http://www.seomoz.org/$1 [L,R=301]
Explanation:
This directive tells apache to examine the host the visitor is accessing (in this case: seomoz.org), and if it does not equal www.seomoz.org redirect to www.seomoz.org. The exclamation point (!) in front of www.seomoz.org negates the comparison, saying “if the host IS NOT www.seomoz.org, then perform RewriteRule.” In our case RewriteRule redirects them to www.seomoz.org while preserving the exact file they were accessing in a back-reference.Redirecting without preserving the filename:
Several files that existed on the old server were no long present on the new server. Instead of preserving the file names in the redirection (which would result in a 404 not found error on the new server), the old files needed to be redirected to the root URL of the new domain.Redirect: http://www.socengine.com/seo/someoldfile.php
To: http://www.seomoz.org/
Solution:
Add the following directive:RedirectMatch 301 /seo/someoldfile.php http://www.seomoz.org
Explanation:
Omitting any parenthesis, all requests for /seo/someoldfile.php should redirect to the root URL of http://www.seomoz.orgRedirecting the GET string:
Some of the PHP scripts had different names but the GET string stayed the same. The SEOmoz developers needed to redirect the visitors to the new PHP scripts while preserving these GET strings. The GET string is the set of characters that come after a filename in the URL and are used to pass data to a web page. An example of a GET string in the URL http://www.seomoz.org/myfile.php?this=that&foo=bar would be “?this=that&foo=bar.”Redirect: http://www.socengine.com/seo/categorydetail.php?CAT_ID=12345
To: http://www.seomoz.org/artcat.php?CAT_ID=12345
Solution:
Add the following directive:RedirectMatch 301 /seo/categorydetail.php(.*) http://www.seomoz.org/artcat.php$1
Explanation:
Once again the regular expression (.*) tells apache to match zero or more of any character and save it as the back-reference $1. Since there is a $1 after /seo/categorydetail.php, it will now redirect the get string to this new PHP file.Redirecting while changing file extensions:
In the original scenario there was a folder of files on the old server that were mixed HTML and PHP. On the new server these files were all PHP and needed redirect logic to change the old URLs to this new extension.Redirect: http://www.socengine.com/seo/guide/anyfile.html
To: http://www.seomoz.org/articles/anyfile.php
Redirect: http://www.socengine.com/seo/guide/anyfile2.php
To: http://www.seomoz.org/articles/anyfile2.php
Solution:
Add the following directive:RedirectMatch 301 /seo/guide/(.*)\.(php|html) http://www.seomoz.org/articles/$1.php
Explanation:
(*.) matches zero or more of any character and saves it as the back-reference $1. \.(php|html) tells apache to match a period followed by either “php” or “html” and saves it as the back-reference $2 (although this isn't used in this example). Notice the escaped period with a backslash. This is to ensure apache does not interpret the period as meaning “any character” but rather as an actual period. Enclosing “php” and “html” in parenthesis and separating them with a pipe “|” character means to match either one of the values. So if it were to say (php|html|css|js|jpg|gif) the regex would match any of the files with the extensions php, html, css, js, jpg, or gif.Conclusion:
By harnessing the power of mod_rewrite and a little regular expression magic the original developers at SEOmoz developed a set of simple rules for redirecting web pages. By using 301 redirects they did this in a way that was search engine friendly.Related Resources
Related Elements
Related Tools
mozBar
The mozBar makes it easier to see relevant SEO metrics as you surf the web.
Open Site Explorer
Open Site Explorer is a free tool that provides webmasters the ability to see up to 10000 links to any site or page on the web via the Linkscape web index.
Linkscape
A professional quality inlink tool that uses patent-pending SEOmoz metrics. Inlinks, anchor text distribution and more.
External Resources
How to create 301 redirects in various programming languages
An example filled article on how to implement 301 redirects.
HTTP Status Codes
W3's official documentation for HTTP Status codes.
301 Redirects from Google
Google's official documentation of 301 redirects.
This article is taken from SEOMOZ. Click here for original post -
Redirection SEO Best Practices | SEOmoz
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.