SEO

23.11.2009 SEO, search engine optimization, server side 1 Comment

Redirecting Web Pages With 301 Redirects

Use 301 Redirects for Rank Preservation and Efficiency

301 Redirects are the most effective and recommended method for moving and redirecting web pages. 301 Redirects tell the search engines the page or website has been permanently moved. Over time, the search engines will update their index to reflect changes and you should see traffic, back links and PageRank flow to the new location. However, if you do not use some sort of redirect, your website might lose search engine rank and visitors.

301 Redirects are typically easy to implement and will help preserve your website’s rankings when moving a page or domain. It is highly recommended that you implement one of the following redirect methods if you want to maintain your search rankings and provide visitors easy access to your new information.

Whenever a website or page has been moved to a new location, it is very important that visitors and the search engines are redirected to the new page or site location. Depending on your server, below are some server descriptions and ways you can implement a 301 redirect depending on your server type and configuration.


Apache Web Server: .htaccess file

The Apache Web server provides a full range of Web server features, including CGI, SSL, and virtual domains. Apache also supports plug-in modules for extensibility. Apache is reliable, free, and relatively easy to configure.

Apache .htaccess files allows you to override the Web server configuration on a directory/hierarchial basis. .htacess files are important in the creation of proper 301 redirects.

Single Page Redirect:

Redirect 301 /old/url /new/url</code>

or

Redirect Permanent /old/ur /new/url

Canonical Hostname Redirect (non-www to www):

This solution will redirect any page requested via a non-www domain to the same URL with the www domain, and as such it can be placed in the DocumentRoot of your site and will be enforced globally:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

Another Example for .htaccess Redirects:

Redirect Old domain to New domain (htaccess redirect)

  1. Create a simple text file using Notepad and name it .htaccess.
  2. Paste the code below into the newly created file.

The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed). Use ftp to do this.

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

Make sure you REPLACE www.newdomain.com in the above code with your actual domain name.

Additionally, I would suggest that you contact every back linking site and ask them to modify their back link to point to your new website.

Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.

Redirect to www (htaccess redirect)

  1. Create a simple text file using Notepad and name it .htaccess
  2. Paste the code below into the newly created file.

The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed). Use ftp to do this.

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

Make sure you REPLACE domain.com and www.newdomain.com with your actual domain name.

Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.


Microsoft IIS Web Server

Note: these instructions require administrative access to IIS. If you do not have this access (e.g., if you have a shared hosting account on a Windows server), you should use one of the server-side scripting methods such as ASP or PHP given further below.

Single Page Redirect:

  1. Open Internet Services Manager and right-click on the file or folder you wish to redirect.
  2. Select the radio button “a redirection to a URL”.
  3. Enter the desitnation page for the redirect.
  4. Check “The exact url entered above” and the “A permanent redirection for this resource”.
  5. Hit “Apply”.

Active Server Pages (ASP)

Active Server Pages or Classic ASP, as it is more commonly known, is a technology that enables you to make dynamic and interactive web pages.

ASP uses server-side scripting to dynamically produce web pages that are not affected by the type of browser the web site visitor is using.

Single .asp Page Redirect:

<%
Response.Status="301 Moved Permanently"
Response.AddHeader='Location','http://www.new-url.com/'
%>

Canonical Hostname Redirect (non-www to www):
This code should be inserted into a global include file or any ASP script which is executed for every page on the site before the page output begins:

<%
If InStr(Request.ServerVariables("SERVER_NAME"),"www") = 0 Then
	Response.Status="301 Moved Permanently"
	Response.AddHeader "Location","http://www."
		& Request.ServerVariables("HTTP_HOST")
		& Request.ServerVariables("REQUEST_URI")
	Response.End
End if
%>

PHP 4 and PHP 5

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.

Single Page .php Page Redirect:

<php
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.new-url.com/');
?>

ColdFusion

ColdFusion is a programming language based on standard HTML (Hyper Text Markup Language) that is used to write dynamic webpages. It lets you create pages on the fly that differ depending on user input, database lookups, time of day or whatever other criteria you dream up!
Single Coldfusion Page Redirect:

<cfheader statuscode="301" statustext="Moved permanently">
<cfheader name="Location" value="http://www.new-url.com/">

Java (JSP) Redirect

JavaServer Pages (JSP) technology provides a simplified, fast way to create web pages that display dynamically-generated content. The JSP specification, developed through an industry-wide initiative led by Sun Microsystems, defines the interaction between the server and the JSP page, and describes the format and syntax of the page.

<%
response.setStatus(301);
response.setHeader( "Location", "http://www.new-url.com/" );
response.setHeader( "Connection", "close" );
%>

CGI PERL Redirect

CGI.pm is a stable, complete and mature solution for processing and preparing HTTP requests and responses. Major features including processing form submissions, file uploads, reading and writing cookies, query string generation and manipulation, and processing and preparing HTTP headers. Some HTML generation utilities are included as well.

$q = new CGI;
print $q->redirect("http://www.new-url.com/");

Ruby on Rails Redirect

Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language. It is intended to be used with an Agile development methodology that is used by web developers for rapid development.

def old_action
headers["Status"] = "301 Moved Permanently"
redirect_to "http://www.new-url.com/"
end

Enspire's Social Media Follow Me Iconenspire twitter profile Enspire's Facebook Profile Enspire's YouTube Profile Enspire's LinkedIn Profile Enspire's Delicious Profile