SEO friendly 301 redirecting process

Programming for Search Engines 101. An area for avid PHP and .NET developers to chat about Programming techniques and how to make better use of search engines.

Moderator: Moderators

SEO friendly 301 redirecting process

Postby Siva » Wed Oct 17, 2007 7:27 am

Technical Aspects of Setting Up 301 Redirects in the .htaccess

If we want to create a new page and want to transfer the Page Rank of the old page to this new one, we must be in the lookout of some visitor or spider friendly method of doing it. Redirecting viewers from the old page to the new one is done best with the help of 301 Redirect. But other directions are not SEO friendly such as s other types of redirects that can serve the same purpose like 302, JavaScript, and Meta Refresh.

If we want redirect any url that should be a 301 permanent redirection

Why 301 Redirect

In fact, If we are using a client-side meta-refresh or a JavaScript redirect, in general the search engine may mistakenly conclude that you are using doorway pages. This is because often the client-side redirects make use of doorway creators in order to feed one version of a page to the visitors and the other version to the search engine spider. In the case of a 302 Temporary Redirect, the Page Rank and other authority factors are not transferred to the new page. This is because the search engine assumes that after a certain period of time, the page will be returned to its original location. Therefore, “301” is the safest method to redirect old pages to new ones.

When to Use 301 Redirects?


In most cases, the “301 Redirect” is used by site owners to transfer their site from “non-www” version of the URL of the site to “www” version. Suppose, your site name is xyz.com. You need to use the 301 Redirect method to redirect the site name to http://www.abc.com. This process is a must as it not only prevents 302 hijacking, but also blends the link popularity of the two and restricts duplicate content filter.

Technical Requirements for 301 Redirect in .htaccess

How ever we Required an Apache server and the .htaccess file. Most of the hosting services that you use has Apache server. The .htaccess file is important as the web checks for it after receiving request from a search engine spider. They add the Redirect to your server’s root command. If done improperly, it may result your site to fail totally, making it unreachable to the users. The 301 is the safest way to Redirect files and also preserve Page Ranks. When the next spidering occurs, the search engine robot obeys the rule that you indicated in .htaccess file. It is not that the search engine spiders actually read .htaccess files, but it identifies the response given by the server as valid.

Canonical Hostname Redirect (non-www to www):
.htaccess file


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


PHP 4 and PHP 5
Single Page Redirect:


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

Canonical Hostname Redirect (non-www to www):


?php
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') {
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.'.$_SERVER['HTTP_HOST']
.$_SERVER['REQUEST_URI']);
}
?

Active Server Pages (ASP)
Single 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
%

Most of the information i have taken from the following link http://www.websitesource.com/tutorials/301-setup.shtml.

Siva
Siva
 

Return to Programming

Who is online

Users browsing this forum: No registered users and 3 guests