How do rel=”next” and rel=”prev” work?

Featured Image

Image by boris_licina

When dealing with online stores with a lot of products, pagination on category pages can get really problematic for search engines. Link juice gets distributed all over the place, your internal linking structure is terrible, indexing of deep page products is difficult and anchor text values that pagination sends have nothing to do with the content of the page, but there was no better way to do it. It came down to choosing between SEO and usability.

Yesterday, Google explained how they look at rel=”next” and rel=”prev” in an official blog post. It solves the great problem of paginated products on category pages of online stores.

The most important thing you need to know is that Google will treat all pages inside the pagination that have rel=”next” and rel=”prev” implemented as one unit in regards to link attribution. This means you no longer need to worry about dispersing your internal link juice to paginated pages or external link juice that’s coming into these pages. They will treat them as a whole and collect link juice from all of them, while shoving the most relevant page in the search result (most often the 1st page of the paginated unit).

I’m actually very impressed by this solution, since the best thing we could do so far was implement a rel=”canonical” which is really applicable in some rare cases I described here, but not in most of the pagination problems (since content of the page 2 is often completely different than the content of the page 1 etc.).

The technical implementation of rel=”prev” and rel=”next” is very similar to the way you implement rel=”canonical”:

It is placed in the head in this form:

<link rel="next" href="http://www.example.com/article?story=abc&page=2"/>

and

<link rel="prev" href="http://www.example.com/article?story=abc&page=1"/>

The first page, obviously, should not have a rel=”prev”.

UPDATE: Google made a video that explains a lot of things about rel prev and rel next:

Need help with your Magento store’s SEO? Request a quote!

5
Top

Enjoyed this post?

Subscribe to our RSS Feed, Follow us on Twitter and spread it to your friends!

Author

Toni Anicic

Ex. Inchooer

Toni worked at Inchoo from 2008 to 2013. as a Marketing Manager.

Other posts from this author

Discussion 5 Comments

Add Comment
  1. Ramesh

    Nice information Toni. This should also avoid duplicate Title and description tag issue too as all pages will be considered as a single unit.

  2. Benjamin

    Hey Inchooers,

    can you actually tell us on how to implement this by code into the html head. I had one solution that was working but had some bugs, such as a rel=”next” metatag on the last page of a paginated page. That should not be the case. Would be great, if you could write a blogpost about it. Thank you so much. I love your website.

  3. This is a (dirty) way to implement next & prev link rel :

    Put this code in your page/html/head.phtml :
    (Or in your customized head.phtml)

    &lt;?php
    	if ($this-&gt;getAction()-&gt;getFullActionName() == 'catalog_category_view')
    	{
    		if ($this-&gt;getLayout()-&gt;getBlock('product_list'))
    		{
    			$limit = Mage::getBlockSingleton('catalog/product_list_toolbar')-&gt;getLimit();
    			$productCollection = $this-&gt;getLayout()-&gt;getBlock('product_list')-&gt;getLoadedProductCollection();
    			$tool = $this-&gt;getLayout()-&gt;createBlock('page/html_pager')-&gt;setLimit($limit)-&gt;setCollection($productCollection);
    			$linkPrev = false;
    			$linkNext = false;
    			if ($tool-&gt;getCollection()-&gt;getSize())
    			{
    				if ($tool-&gt;getLastPageNum() &gt; 1)
    				{
    					if (!$tool-&gt;isFirstPage())
    					{
    						$linkPrev = true;
    						if ($tool-&gt;getCurrentPage() == 2)
    						{
    							$url = explode('?', $tool-&gt;getPreviousPageUrl());
    							$prevUrl = $url[0];
    						} else {
    							$prevUrl = $tool-&gt;getPreviousPageUrl();
    						}
    					}
    					if (!$tool-&gt;isLastPage())
    					{
    						$linkNext = true;
    						$nextUrl = $tool-&gt;getNextPageUrl();
    					}
    				}
    			}
    			if ($linkPrev) echo '&lt;link rel=&quot;prev&quot; href=&quot;'. $prevUrl .'&quot; /&gt;'.&quot;\n&quot;;
    			if ($linkNext) echo '&lt;link rel=&quot;next&quot; href=&quot;'. $nextUrl .'&quot; /&gt;'.&quot;\n&quot;;
    		}
    	}
    ?&gt;
    

    Cheers,

    Ilan

  4. Hans Kuijpers

    for those who visit this page through a search engine…. please continue to read on http://inchoo.net/ecommerce/magento/how-to-implement-relprev-and-relnext-to-magentos-pagination/

    An excellent implementation of rel next and prev via an overide on .phtml files and an implementation using an extension.

  5. You’re the man Ilan! it works like a charm! Thank you very much! :)

Add Your Comment

Please wrap all source codes with [code][/code] tags.
Top