All-In-One SEO Pack Breaks Canonical URLs of Multi-Page Posts & Pages

There is a bug in All In One SEO Pack that affects Canonical URLs of multi-page posts and pages on WordPress-based sites. This bug causes all sub pages of a multi-part post or page to have the Canonical URL of the base page itself. While this may not sound like a serious problem, it severely affects SEO of a website and prevents indexing of the sub pages.

What are Canonical URLs?

A Canonical URL is an “official” URL of a web page. From a search engine’s point of view, the same page can appear to be many different pages due to small changes in the page’s URL, such as a trailing slash or a query parameter. For example, http://site-url/page-url and http://site-url/page-url/ can appear to be two different pages to a search engine, even though in reality they point to the same page. By using a Canonical URL tag as shown below, the web page can let the search engine know what its actual URL is:

<link rel="canonical" href="http://site-url/page-url" />

So if a search engine were to reach the same page by following different URLs, it can now figure this out by looking at the Canonical URL tag. The benefit of this is much cleaner indexing of a website by including only unique pages and eliminating duplication of content.

Canonical URLs

Problem with Canonical URLs in All In One SEO Pack

On WordPress, when a post or page that is further split into sub pages, the sub pages will have URLs of the form http://site-url/page-url/sub-page-number, where sub-page-number ranges from 2 to the number of sub pages. Due to the above mentioned bug in All In One SEO Pack, all of the sub pages will have the Canonical URL of the base page, i.e. http://site-url/page-url.

The serious side effect of this on the website’s SEO is that Google, Bing and other search engines that support Canonical URLs will essentially index only the base post or page URL and ignore the sub pages. So although all sub pages will be crawled, only the base post or page URL will ever appear in a search result, even if the matching content actually resides on a sub page. This will cause the following problems:

1. It will mean that a lot lesser URLs than actually exist will be indexed by search engines, since the sub pages of multi-page posts and pages will be ignored

2. It will serve to confuse users reaching the base page through a search result, as s/he will not find the content s/he was looking for if that is on a sub page and not on the base page.

How to fix the problem

The fix for this issue is very simple. You need to add the following lines of code at line 349 in all-in-one-seo-pack/aioseop.class.php (see highlighted portion):

if ($url) {
  $url = apply_filters('aioseop_canonical_url',$url);
 $exploded_url = explode("/",$_SERVER['REQUEST_URI']);
 if( is_numeric( $exploded_url[sizeof($exploded_url)-1] ) ) {
 $url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
  echo "".'<link rel="canonical" href="'.$url.'" />'."\n";

Let me know if you face any issues with this fix.



  1. Muhammad WaqasMuhammad Waqas02-10-2014

    Vijay hope you are fine. I still have a problem event implement the changes you mention above please help me to resolve this issue. I am using All in One SEO Version 2.1.3 | By Michael Torbert

    Looking forward for your reply


    • Vijay PadiyarVijay Padiyar02-11-2014

      Sorry, I don’t use All In One SEO Pack anymore as my WordPress theme has built-in SEO support.

  2. Ashutosh JoshiAshutosh Joshi01-20-2013

    Hey Vijay! You yourself not having the right canonical URLs for sub-pages of category.. ! 😉

    • Vijay PadiyarVijay Padiyar01-20-2013

      Looks fine to me. Can you tell me which sub-pages you are referring to?

  3. Joker-jarJoker-jar07-16-2012

    if( is_numeric( $exploded_url[sizeof($exploded_url)-1] ) ) {

    could be writed as

    if ( is_numeric( end($exploded_url) ) ) {

    Some wordpress sites has / at the end of urls. So, i think, the better way is use something like this:

    $exploded_url = preg_split(“///”, $_SERVER[‘REQUEST_URI’], -1, PREG_SPLIT_NO_EMPTY);
    if ( is_numeric( end($exploded_url) ) ) {
    $url = “http://”.$_SERVER[‘HTTP_HOST’].$_SERVER[‘REQUEST_URI’];

  4. NeeshuNeeshu05-29-2012

    I have been using read more option in all the posts of on my website, i have also enabled cannonical option in the all in one seo do you think i need to change the code as directed by you or has the all in one seo made any updates in this regard

    • Vijay PadiyarVijay Padiyar05-29-2012

      Canonical option in All-In-One SEO Pack only enables canonical tags. The tags are fine for regular pages but not for multi-page pages (i.e. pages that are broken into multiple sub-pages). I guess the problem should be there for multi-page posts as well. To fix that, you need my patch.

Leave a Reply