301 redirects – On Page – with PHP and ASP

29th May 2007 by Hannah Parker

Sometimes I have to deal with sites where the owner has several domains and they have used server aliasing to point all domains to the same webspace – effectively all domains serve the same content – duplicate content extraordinaire.


Take this scenario. The client has 2 domains:


www.original-domain.co.uk


www.second-domain.co.uk


The original-domain was registered first and the second-domain has a server alias to the original-domain. This means that both domains return a header status of 200 and both show identical content – although they are actually looking at the same copy of the files.


Unfortunately the client wants to promote the second-domain. The original-domain is indexed in Google and the second-domain only has the homepage indexed because it’s perceived (fairly so) to be a duplicate site.


So what your friendly SEO team want to do is implement a 301 redirect from orginal-domain to second-domain. Hence telling the search engines that the second-domain is now the site to index.


But then you’re hit with an IIS Server with no .htaccess file AND an unco-operative web hosting company – who insist that server aliasing is perfectly SEO friendly. So what do you do….?


Well this solution requires server side scripting to enabled. Because both domains are looking at the same page – you can create the 301 redirect on page – here is the sample PHP script you’d use to solve the issue with the above example domains:


<?php
if ($_SERVER['HTTP_HOST'] == “www.original-domain.co.uk“)
{
//redirect
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: www.second-domain.co.uk“);
//exit;
}


?>


And in ASP:


<%
  dim domainName
  domainName=request.ServerVariables(“SERVER_NAME”)
  if StrComp(domainName,

Related Posts

  1. 301 Redirects don’t transfer 100% of PageRank
  2. SEO Speak – Header Status
  3. SEO Speak: What is a 301?
  4. Moving Web Content in a Server Side Technology Independant Way
  5. Canonical Tag as 302 Resolution in Google
  6. How long does it take for 301 redirects to transfer PageRank?
  7. Google focuses on 404 error pages for SEO
  8. Are 301 redirects really needed on my new website design?

Comments are closed.

  • CONTACT

    1. Captcha