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

How do rel=”next” and rel=”prev” work? © 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!

Related Inchoo Services

You made it all the way down here so you must have enjoyed this post! You may also like:

Google manually punishes bloggers with paid product reviews Toni Anicic
Toni Anicic, | 4

Google manually punishes bloggers with paid product reviews

What is schema.org and what about my rich snippets? Toni Anicic
Toni Anicic, | 14

What is schema.org and what about my rich snippets?

How to track internal site search with Google Analytics? Toni Anicic
Toni Anicic, | 6

How to track internal site search with Google Analytics?

5 comments

  1. 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)

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

    Cheers,

    Ilan

  2. 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. Nice information Toni. This should also avoid duplicate Title and description tag issue too as all pages will be considered as a single unit.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <s> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.

Tell us about your project

Drop us a line. We'd love to know more about your project.