Best Wordpress Plugins: Enforce www. Preference
June 9, 2008 by Tony | Tag(s): 301 Redirect, Wordpress Plugins
WWW or no-WWW?
Whenever you create a website or a blog it usually can be accessed either through “http://www.domain.com” or “http://domain.com”. While this feature might appear useful at a first sight (since people can type whatever version they prefer) over the long run it will harm your search engine ranking.
The problem arises because Google and other search engines view the two versions as two distinct sites, even if they have the exact same content (technically, in fact, the “www” denotes a subdomain that could point to different content).
Search engine ranking is based, among other things, on the number of incoming links to your site. If you keep the two versions available some people will link to “http://www.domain.com” while other people will link to the “http://domain.com”, basically splitting your backlink count.
Having two different versions might damage you in popular lists and social bookmarking sites as well. The picture on the right was extracted from Populicious, a site that lists the most popular sites on Delicious. If you take a look you will notice that Digg is listed both at the 7th and 10th position. This happens because the list treats “http://www.digg.com” and “http://digg.com” as two different sites. Shoud only one version be available the combined number would place Digg on the first position of the list.
How do you solve the problem for your blog? The easiest way is to set up a “301 Permanent Redirect” from the “no-www” version to the one with “www”, or vice-versa. Once the redirect is in place every time a visitor types http://domain.com he will automatically be redirected to the “www” version.
By the way, if you are wondering whether you should go with or without “www”, it does not matter. The important thing is that you pick one and stick with it.
How to setup a 301 Redirect
The “301 Permanent Redirect” is the most efficient and search engine friendly method for redirecting websites. You can use it in several situations, including:
- to redirect an old website to a new address
- to setup several domains pointing to one website
- to enforce only one version of your website (www. or no-www)
- to harmonize a URL structure change
There are several ways to setup a 301 Redirect, below I will cover the most used ones:
PHP Single Page Redirect
In order to redirect a static page to a new address simply enter the code below inside the index.php file.
<?php
header(”HTTP/1.1 301 Moved Permanently”);
header(”Location: http://www.newdomain.com/page.html”);
exit();
?>
PHP Canonical Redirect
The Canonical 301 Redirect will add (or remove) the www. prefixes to all the pages inside your domain. The code below redirects the visitors of the http://domain.com version to http://www.domain.com.
<?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']);
}
?>
Apache .htaccess Singe Page Redirect
In order to use this method you will need to create a file named .htaccess (not supported by Windows-based hosting) and place it on the root directory of your website, then just add the code below to the file.
Redirect 301 /old/oldpage.htm /new/http://www.domain.com/newpage.htm
Apache .htaccess Canonical Redirect
Follow the same steps as before but insert the code below instead (it will redirect all the visitors accessing http://domain.com to http://www.domain.com)
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
ASP Single Page Redirect
This redirect method is used with the Active Server Pages platform.
<%
Response.Status=”301 Moved Permanently”
Response.AddHeader=’Location’,'http://www.new-url.com/’
%>
ASP Canonical Redirect
The Canonical Redirect with ASP must be located in a script that is executed in every page on the server before the page content starts.
<%
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(”SCRIPT_NAME”)
End if
%>
Best Wordpress Plugins: Enforce www. Preference
It it always a good idea to decide if you want to make your website accessible through http://www.domain.com or http://domain.com, and stick with it. Having both of those versions working might split your backlink count and cause problems with search engine indexation (you can read more about it on the article WWW or no-WWW?.
The best way to solve this problem is to set a 301 redirect. Sometimes, however, you might find it difficult to get the PHP code working or your server might not support the .htaccess redirect. In that case you can turn to a Wordpress plugin called “Enforce www. Preference”.
Once you upload and activate the plugin it will enforce the address that you have on the Wordpress control panel (under the General tab on Options). If on the control panel you have http://www.domain.com, for instance, the plugin will add a www. every time a visitor tries to access the site through http://domain.com. Another advantage of this plugin is that it removes the index.php from the end of URIs.

![Subscribe to [Blog Tutorials]](http://blogtut.com/wp-content/themes/BlogTutorialPro/images/rss.gif)
![[del.icio.us]](http://blogtut.com/wp-content/plugins/bookmarkify/delicious.png)
![[Digg]](http://blogtut.com/wp-content/plugins/bookmarkify/digg.png)
![[Facebook]](http://blogtut.com/wp-content/plugins/bookmarkify/facebook.png)
![[Google]](http://blogtut.com/wp-content/plugins/bookmarkify/google.png)
![[MySpace]](http://blogtut.com/wp-content/plugins/bookmarkify/myspace.png)
![[Newsvine]](http://blogtut.com/wp-content/plugins/bookmarkify/newsvine.png)
![[Reddit]](http://blogtut.com/wp-content/plugins/bookmarkify/reddit.png)
![[Slashdot]](http://blogtut.com/wp-content/plugins/bookmarkify/slashdot.png)
![[StumbleUpon]](http://blogtut.com/wp-content/plugins/bookmarkify/stumbleupon.png)
![[Technorati]](http://blogtut.com/wp-content/plugins/bookmarkify/technorati.png)
![[Windows Live]](http://blogtut.com/wp-content/plugins/bookmarkify/windowslive.png)
![[Yahoo!]](http://blogtut.com/wp-content/plugins/bookmarkify/yahoo.png)
![[Email]](http://blogtut.com/wp-content/plugins/bookmarkify/email.png)






Comments
Feel free to leave a comment...
and oh, if you want a pic to show with your comment, go get a gravatar!