What is the Canonical Domain Issue?
This occurs when there isn’t a Permanent Redirect (301) found at the root level of your domain. If not configured properly, search engines will treat your domain “http://example.com” and “http://www.example.com” as two different sites. This can seriously hurt your rankings! We will use that same domain name in the code examples in this tutorial.
Why is it so Critical?
This issue gets so much attention because it’s such a simple mistake that can hurt your rankings an incredible amount. It also gets written about often because the fix is relatively simple (with the proper instruction). Follow the instructions below to make sure you get the “Full Credit” from every search engine.
How Can I Check My Website for This Canonical Domains Problem?
The easiest way to test if your site has this issue is to run it through one the following analyzers.
They both will tell you very clearly if there are any canonical domain erros, as well as provide you other information about your domain that is often over looked.
Here’s How to Fix It:
There are many ways to fix the canonical domain issue. The first example is by using an Apache .htaccess file with the following contents. If your preferred name is http://www.example.com, then add the following to a blank text file named .htaccess, and upload it to the domain root:
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^example.com [nc]
rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]
Conversely, If your preferred domain is http://example.com then your last two lines would be:
rewritecond %{http_host} ^www.example.com [nc]
rewriterule ^(.*)$ http://example.com/$1 [r=301,nc]
If you website is built in PHP, you can fix it with the following code snippet:
<?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']);
}
?>
And Finally, a 301 Canonical redirect using ASP:
<%
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
%>
How Can I Verify The Fix?
After making the above changes, re-run your website through the analysers that I linked previously. The fix should take effect immediately.
I hope found this article informative. If you have any questions or comments, feel free to enter them below.



