2 Domain to 1 Site – The 301 Redirect
This is a question I get asked all the time, and since I’m in the process of setting up this new site it seemed like an ideal case study to show you how to do it properly.
Many times I have a client who wants to register more than one domain, and have them all point to the same site. Often done to protect the domain from possible abuse (hijacking by someone else taking a very similar domain to ’steal’ your traffic) or simply to catch mis-typed type-in traffic (where a user keys your domain into their browser address bar).
For this site I registered both the hyphenated, and non-hyphenated versions of the domain, primarily since in my experience the double S will often get mis-typed in the non-hyphenated version, while in the hyphenated version it’s easier to spot the mistake!
Now, the problem comes from Google’s penalisation of duplicate content. Google, and the other search engines, are in the business of offering quality and unique search results to their users. Therefore multiple sites with the same content are penalised and don’t rank well. The way to get around this is to use a 301 Redirect on all but the primary domain. In this example, online-business-logic.com is the primary domain and actually hosts the site while onlinebusinesslogic.com has a 301 redirect which ‘points’ the domain to this site while being ignored by the search engine spiders. The code 301 is interpreted as ‘page permanently moved’ and is also used if, for some reason, you have to move content on a site, perhaps if you move from a static site to a CMS and the structure changes, or you change file extensions from .html to .php in order to add dynamic content.
Here’s how to accomplish this…
In PHP
<?php
// Permanent redirection
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.your-domain-here.com/");
exit();
?>
In ASP
<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.your-domain-here.com/"
%>
In CGI Perl
$q = new CGI;
print $q->redirect("http://www.your-domain-here.com/");
In JSP
<% response.setStatus(301); response.setHeader( "Location", "http://www.your-domain-here<.com/" ); response.setHeader( "Connection", "close" ); %>
Simply create a new page using the code for the method of your choosing and save it as the index file on the domain you want to redirect, changing http://www.your-domain-here.com to the URL of the page you want to redirect to.
The redirect can also be done using a .htaccess file (on Linux servers which have mod-rewrite enabled) with the following code:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^your-domain-here.com [nc]
rewriterule ^(.*)$ http://www.your-new-domain-here.com/$1 [r=301,nc]
Create a plain text file with the above code, save it as .htaccess (That is the entire filename, ‘.htaccess’, with nothing before the period.) and upload it to the root directory of the domain you want to redirect.
Et voilĂ , clean redirects and no duplicate content penalty!


















Thanks alot for this, i was searching for the php code to accomplish this and it works perfectly
cheers
Leave your response!