It'd be good to do something like that, since between subdomains I can have repeated content and that's not good for SEO...

http://www.mattcutts.com/blog/canonical-link-tag-video/

It's a video and a presentation from the "Google's Webspam team head", explaining why to do that. And it appears to be reasonable simple to do.

Thanks for attention!

Comments

mr.j’s picture

Vuds I agree, its odd that this has been ignored as it is quite important in SEO terms. This is another good article on the subject:
http://www.seomoz.org/blog/canonical-url-tag-the-most-important-advancem...

Perhaps nodes that have been flagged with "Send to all affiliates" could have the canonical url tag added to the head of the document (pointing to the root domain) when viewed.

This would allow you to share nodes across multiple domains without incurring duplicate content penalties. It avoids the need to rewrite URLs (as provided by the SEO setting), which can be annoying or confusing for the user if the domains are structured or themed differently.

agentrickard’s picture

Instead of a documentation link, can someone just post what the final <a> tag output is supposed to look like?

Or a patch?

mr.j’s picture

Its not actually an <a> but a <link> tag that goes in the page header and just tells the search engines which url should be treated as the canonical version.

Say you have a node that is sent to all affiliates:
hxxp://www.mysite.com/forum/topic

Then you can view it on other subdomains but its essentially the same content
hxxp://sub1.mysite.com/forum/topic
hxxp://sub2.mysite.com/forum/topic

So when viewing the node on the subdomains, you add a link tag like this inside the page <head> element.
<link rel="canonical" href="hxxp://www.mysite.com/forum/topic" />

This tells the search engine to funnel any link juice to the root domain canonical URL and not penalise you for having duplicate content. The added benefit for a user is that you don't have to rewrite URLs to the root version any more and force the user to navigate across subdomains to view content.

I knocked something up quickly last night that I have put into my page.tpl.php to solve the problem I had with sharing a forum across multiple subdomains. Its a quick hack because I only really needed it for my forums but it serves its purpose:

$uri = request_uri();
if (strpos($uri, '/forum') == 0) {
  $host = explode('.', $_SERVER['HTTP_HOST']);
  if ($host[0] != 'www') {
    $host[0] = 'www';
    $canonicalUrl = '<link rel="canonical" href="http://' . implode('.', $host) . $uri . '" />';
  }
}

if (isset($canonicalUrl) print $canonicalUrl;

I also needed to patch custom_url_rewrite_outbound so that it would not rewrite URLs for nodes which have been published to all affiliates, or the current domain when it is not the first selected domain (in the multiple but not all domains case).

No doubt people would want the option to decide when/where to use it and it needs to integrate with the SEO rewriting option (which I still use for nodes which have only been published to a single domain). Nodes published to all affiliates is the easy case, but there's also the case of nodes published to multiple, but not all, affiliates.

agentrickard’s picture

Thanks!

agentrickard’s picture

Version: 6.x-2.0-rc6 » 6.x-2.0-rc8
Status: Active » Postponed

I would still love to see a patch for this.

promes’s picture

I created a redirect module for DA. It will redirect a node to a assigned domain whenever the node is requested from another domein. It has several settings to match your situation.
One of them is the creation of canonical URL tags. I have it working on five life sites.
Since this module will not be added to the DA-core I try to get an CVS account to publish this module on this site.

I created a testsite with a download option for those interested in the module. I added also canonical links to the module as an option.
Have a look at: http://domain1.drupalhandboek.nl/en/domain-redirect

agentrickard’s picture

Status: Postponed » Closed (won't fix)

Canonical links are in Drupal 7 by default. I am not going to backport this to D6.

jordanmagnuson’s picture

Bummer that this isn't coming to Drupal 6... would a backport really be so difficult? Is the solution more troublesome than the kind of code mr j has in #3?

agentrickard’s picture

"I am not going to backport" doesn't mean I won't accept a patch. You want to build it, re-open the issue and assign it to yourself.

The D6 version is closed to new features.

jordanmagnuson’s picture

Sorry Ken, didn't mean to come across as ungrateful or demanding! I really appreciate everything you've done with this fantastic module, and totally understand that you may be too busy to backport this to D6. I'm afraid I haven't gotten to the stage of understanding exactly how to create and contribute patches, but I hope to be there soon.

agentrickard’s picture

Status: Closed (won't fix) » Active

I think in this case it's a fairly simply drupal_set_html_head() call. The question is where does it go? node_view()? hook_init()?

agentrickard’s picture

Status: Active » Needs review
StatusFileSize
new1.2 KB

Simple. Like so.

agentrickard’s picture

StatusFileSize
new1.09 KB

Fixes spacing issue.

agentrickard’s picture

StatusFileSize
new1 KB

Very likely safer to do in hook_init(). This will only affect nodes. Could be made to post for any link, but really, that's the task of another module.

Are there other modules that do this in D6?

mr.j’s picture

Yes, canonical_url and nodewords do it too. Global redirect as well.

agentrickard’s picture

Status: Needs review » Closed (won't fix)

In d6 I would suggest you use those, since DA only handles nodes. Or you can put the above code in a custom site module.

jwilson3’s picture

The Canonical_URL module has been deprecated in favor of NodeWords, and there is an integration module that hooks NodeWords up to the Domain Access module called Domain_Meta. The currently recommended version from the NodeWords maintainers is to use the 6.x-1.x-dev branch of nodewords, which should be compatible with Domain_Meta. This seems to be the most logical approach (using the domain configurations on a given page/view etc from DA to set the canonical url meta tag provided by NodeWords) however, since both modules involved require dev branches, I have to suffix this with a "use at your own risk", and "patches welcome" ;)

jwilson3’s picture

Patch provided to Domain_Meta module: your reviews are welcome: #1245660: Support for Canonical URLS