Question:
How do I set up a 301 redirect because my website resides at both www.site.co.uk and site.co.uk?
Colin B
2012-03-09 09:37:49 UTC
I visited http://www.aboutus.org/ and it told me that I need to set up a 301 redirect for the reason I stated in my question.

The thing is, I'm a novice and I didn't purposely set up the website to be that way and I didn't even know about a 301 redirect until the above site recommended that course of action. I just assume that both addresses linked to the same site and didn't influence SEO at all but now I know that it does.

Thanks.

PS. I'm usng Joomla CMS.
Three answers:
2012-03-11 10:14:18 UTC
I think the reason why aboutus.org told you to do that is in order to avoid duplicate content in the search engines.



This post http://www.itoctopus.com/how-to-handle-duplicate-content-on-your-joomla-website examines the issue of duplicate content, its effects on SEO, and what you can do to fix it (including doing a 301 redirect from the www version to the non-www version or vice versa.
?
2012-03-09 11:08:32 UTC
Many hosting accounts have a control panel setting that remaps the address any visitors see to the preferred form, adding or removing the .www to match your preference, this way any bookmarks or address copies a visitor makes reinforce the preferred form. There is also a cryptic script one can add to a lenux server .httaccess file to accomplish this. I have not heard of 301 redirects typically being commonly used for this purpose.



The www issue is not a huge deal, you will find some backlinks get created using both forms, which can dilute the seo strength of each since, at least until recently the 2 versions were treated like different sites by search engines.



Google's response to some sites attempting to use subdomains to to isolate low ranking pages in order to counter the effect of the Panda filter was to change their policy, they now treat subdomains more like part of the same part of the site, much like directories. The point being a www. is effectively a subdomain and may now make less difference to the ultimate search ranking of a site.
Shamo
2012-03-09 10:25:30 UTC
It is normal practice to have domains linked and accessed via the www version. However, if you prefer the non www version, just reverse the following:



To redirect all traffic from http://site.co.uk to http://www.site.co.uk (and also redirect all other domains parked into the same web space)



RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\.site\.co\.uk

RewriteRule (.*) http://www.site.co.uk/$1 [R=301,L]





To redirect http://www.site.co.uk/index.html to http://www.site.co.uk. Change to .htm or .shtml depending on your requirements and http://www.site.co.uk/index.php to http://www.site.co.uk



RewriteEngine on

Options +FollowSymLinks

RewriteCond %{THE_REQUEST} ^.*/index\.html

RewriteRule ^(.*)index.html$ http://www.site.co.uk/$1 [R=301,L] RewriteCond %{THE_REQUEST} ^.*/index\.php

RewriteRule ^(.*)index.php$ http://www.site.co.uk/$1 [R=301,L]



How to do a 301 redirect



If you ever need to do a redirect in PHP code, make sure that you do more than just the default - ie not just the R, but the R=301 in the htaccess, or not only the "Location", but also the initial 301 Moved Permanently code. The default redirect is a non search engine friendly 302 temporary redirect.



A 301 redirect is a search engine safe way redirecting traffic.



In PHP



This PHP code must appear before any output is sent to the browser.



if(preg_match("/[index.php]$/",$_SERVER[REQUEST_URI]))

{



$url="http://".$_SERVER[HTTP_HOST].preg_replace("/(index.php)$/","",$_SERVER[REQUEST_URI]);

$sapi=php_sapi_name();

if (PHP_VERSION >= '4.3.0')

{

header("Location: $url", 0, 301);

}

else if ($sapi == 'cgi' OR $sapi == 'cgi-fcgi')

{

header("Location: $url");

// Call the status header after Location so we are sure to wipe out the 302 header sent by PHP

header('Status: 301 Moved Permanently');

}

else

{

header("Location: $url");

header('HTTP/1.1 301 Moved Permanently');

}

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...