Question

I am new in using the zend framework. I have searched but didn't get a solution on how to create canonical links using zend framework 1.

The rel attribute of the link element should have canonical, next and previous depending on the page you are on.

E.g When on this page (www[dot]example.co.uk/index/testimonials/), the link should be:

<link rel="canonical" href="http://www.example.co.uk/index/testimonials/”/> <link rel="next" href="http://www.example.co.uk/index/testimonials/page/2”/>

Was it helpful?

Solution

I have done it a different way in my view/script file;

        $this->headLink(array('rel' => 'canonical', 'href' => 'http://www.example.com/index/news?page=1'));
        if ($this->page < count($this->newsList)){
            $this->headLink(array('rel' => 'next', 'href' => 'http://www.example.comk/index/news?page='.($this->page + 1)));
        }
        if ($this->page > 1) {
            $this->headLink(array('rel' => 'prev', 'href' => 'http://www.www.example.com/index/news?page='.($this->page - 1)));
        }

OTHER TIPS

If you need to generate a canonical URL (having the scheme and host name), you can specify the third parameter for the Url view helper. The third parameter should be an array containing one or several options. For assembling the absolute URL, pass the force_canonical option, as in the example below:

<!-- A hyperlink to Home page -->
<a href="<?php echo $this->url('home', array(), 
  array('force_canonical' => true)); ?>" > Home page </a>

<!-- A hyperlink to About page -->
<a href="<?php echo $this->url('application/default', array(
  'controller' => 'index', 'action' => 'about'),
  array('force_canonical' => true)); ?>" > About page </a>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top