How to fix Drupal’s Canonical errors

I’m writing this because if you are like me and experiencing issues with canonical errors on a new Drupal site, a killer SEO problem, much of what you will find on Google will reference two types of fixes, however the one you need probably won’t pop up.

I found this very annoying as SEO with Drupal is such a saturated topic. But it wasn’t until I was looking through the documentation for the module XML Sitemap that I found out what was causing the canonical error, my settings.php file.

To fix the canonical error of a Drupal site, make sure in your settings.php file that you uncomment the following line:

$base_url = ‘http://www.yoursite.com’; // NO trailing slash!

With a typical install of Drupal you’ll most likely find this file in var/www/html/sites/default/settings.php

So that’s what I had missed, but this alone is not the only thing you’ll have to do. You may have already done it, but next is editing your .htaccess file to uncomment the following lines (note: they are not next to each other, though if you have no .htaccess file you can just make a text file with this info)

Options +FollowSymLinks
RewriteEngine on
RewriteBase / //note: this is if your site runs from http://www.yoursite.com and not http://www.yoursite.com/drupal other wise use RewiteBase /drupal
RewriteCond %{HTTP_HOST} !^yoursite.com$ [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [R=301,NC,L]

This should typically fix things, but I went a step further and placed the following in my themes page.tpl section:

Likewise, if you are looking for the “essential” SEO modules, I’d advise you to read this great post on the subject of SEO for Drupal here.

You should also have an account with Google.com/Webmaster and under your Site Configuration select Settings and then tell Google that you prefer www.yoursite.com for your site instead of yoursite.com

-fin-

1 Comment

  1. Murray Belflower

    Thanks for the facts about that. I wrote it off as yet another expense, but I’m going to look into it once again.

Leave a Reply to Murray Belflower Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.