Documentation

Light-weight, fast, simple and powerful!
 
Translations of this page?:

Introduction

The notes that follow explain how to set up canonical links in Wolf CMS. You can read up what the purpose of canonical links are here http://en.wikipedia.org/wiki/Canonical_meta_tag.

Usage

1. Create a snippet, e.g. called canonical

<?php 
 $suffix = URL_SUFFIX;  
 $base_url = BASE_URL;
 $current_uri = CURRENT_URI;
 
 if (empty($current_uri)) { 
   $suffix = '';
 }
 
 echo $base_url . $current_uri . $suffix;
?>

2. Include the snippet you layout

<link rel="canonical" href="<?php $this->includeSnippet('canonical'); ?>" />

For clean paging using mod_rewrite

Please note, it makes no sense to add a canonical url in the form of http://mydomain.com/articles?page=2, since the purpose is to give e.g. google a clean seo compatible url. Thus, in the above code paging is ignored and the correct canonical link for such a page would simple be http://mydomain.com/articles.html

However, if you have modified your mod_rewrite, to rewrite it for clean paging, then you could do this instead. For example, I rewrite my pagination for articles to http://mydomain.com/articles/page/3. Thus, in the above snippet code I have the following:

<?php
 $suffix = URL_SUFFIX;  
 $base_url = BASE_URL;
 $current_uri = CURRENT_URI;
 $page = (isset($_GET['p']) ? intval($_GET['p']) : '');
 
 if (!empty($page)) { 
   $suffix = '/page/'.$page; 
 } elseif (empty($current_uri)) { 
   $suffix = '';
 }
 
 echo $base_url . $current_uri . $suffix;
?>

By the way, here is my mod_rewrite syntax for clean paging. Be aware its for the lighttpd webserver http://www.lighttpd.net

  url.rewrite-once = (
	"^(.*)/page/([0-9]+)$" => "/index.php?WOLFPAGE=$1&p=$2"	
  )
  url.rewrite-if-not-file = (
	"^/(.*)$" => "/index.php?WOLFPAGE=$1"
  )
 
tutorials/canonical_links.txt · Last modified: 2011-09-12 00:46 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2
Copyright 2010 wolfcms.org / design by yello studio / Wolf CMS Inside