Community Forums

Canonical URLs and page titles / internal links

General support for technical problems with OpenCart v1.x

Canonical URLs and page titles / internal links

Postby countzer0 » Fri Nov 11, 2011 11:36 am

I am concerned about the way canonical URLs are used in OpenCart. I am using SEO friendly URLs and my site has been indexed under the www.sitename.com/product-name.html URL instead of www.sitename.com/category/sub-category/ ... -name.html or www.sitename.com/manufacturer/product-name.html. All well and good except for this:

1. I am using optimised page titles of the format "Product - Category - Site Name". The canonical URL is not in a category so the titles indexed become "Product - - Site Name". Not good for SEO or click-throughs.

2. The canonical URL pages do not have expanded navigation or breadcrumbs. This means that the internal linking which allows Google etc. to calculate the internal linking hierarchy of the site is non-existent: in effect, all pages are at the top-level, and the category/sub-category pages are very weakly cross-linked. Again, not good for SEO.

Is it possible to force the canonical URLs to be of the format www.sitename.com/category/sub-category/ ... -name.html? I am using 1.5.1.1.
Brighton Guitars, happily using OpenCart 1.5.3.1.
countzer0
 
Posts: 47
Joined: Sat Jun 18, 2011 3:09 pm

Re: Canonical URLs and page titles / internal links

Postby wernerrenrew » Fri Nov 11, 2011 1:07 pm

Hi,

Been thinking about making a module for this just didn't get around doing it.
Anyone else want this one so that i can give this a higher priority.

Regards Werner.
User avatar
wernerrenrew
 
Posts: 170
Joined: Thu Oct 27, 2011 1:48 pm
Location: Netherlands

Re: Canonical URLs and page titles / internal links

Postby uksitebuilder » Fri Nov 11, 2011 4:47 pm

The reason it is not done by default is due to you being able to add a product to multiple categories

If you do that (add to multiple) then the product page will not know which categories to use for the canonical URL.

However, if you only add your products to one category (be that a main cat or subcat - but not both) then it is feasible to change the canonical URL to the structure you want.

To do so, edit: catalog/controller/product/product.php

Find
Code: Select all
$this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');


change to
Code: Select all
if($this->model_catalog_product->getCategoryPath($this->request->get['product_id'])!='0'){
    $this->document->addLink($this->url->link('product/product', 'path=' . $this->model_catalog_product->getCategoryPath($this->request->get['product_id']) . '&product_id=' . $this->request->get['product_id']), 'canonical');
}else{
    $this->document->addLink($this->url->link('product/product', 'product_id=' . $this->request->get['product_id']), 'canonical');
}


edit: catalog/model/catalog/product.php

find
Code: Select all
}
?>


add before

Code: Select all
   public function getCategoryPath($product_id) {
      $query = $this->db->query("SELECT COUNT(product_id) AS total, category_id as catid FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
      
      if($query->row['total']==1){
         $path = array();
         $path[0] = $query->row['catid'];
         
         $query = $this->db->query("SELECT parent_id AS pid FROM " . DB_PREFIX . "category WHERE category_id = '" . (int)$path[0] . "'");

         $parent = $query->row['pid'];
         
         $p = 1;
         while($parent>0){
            $path[$p] = $parent;
            
            $query = $this->db->query("SELECT parent_id AS pid FROM " . DB_PREFIX . "category WHERE category_id = '" . (int)$parent . "'");
            $parent = $query->row['pid'];
            $p++;
         }
      
         $path = array_reverse($path);
         
         $fullpath = '';
         
         foreach($path as $val){
            $fullpath .= '_'.$val;
         }
      
         return ltrim($fullpath, '_');
      }else{
         return '0';
      }
   }         


I have added a fallback in the above so if you do list the product in more than one category, it will default to how the canonical url currently works.

There's probably an easier way to do the above, but it was requested for one of my extensions and it works.

vqmod file if you want it:

uksb_product_canonical.xml
(2.22 KiB) Downloaded 379 times
User avatar
uksitebuilder
 
Posts: 5602
Joined: Thu Jun 09, 2011 3:37 pm
Location: United Kindgom

[Solved]: Canonical URLs and page titles / internal links

Postby countzer0 » Sat Nov 12, 2011 12:26 am

Wow Simon, this is exactly what I needed, thank you so much. Problem solved!
Brighton Guitars, happily using OpenCart 1.5.3.1.
countzer0
 
Posts: 47
Joined: Sat Jun 18, 2011 3:09 pm

Re: Canonical URLs and page titles / internal links

Postby jordan » Sun Nov 27, 2011 9:04 am

I found this thread since I am looking for the same thing. Changing canonical url to category/product, however I do need to have products in multiple categories. I was thinking to have a way to either select a "primary category", or a way to explicitely override the canonical url. Has anyone attempted to solve this?

Presumably the DB schema would have to be modified to either store canonical url or default category in the product table or in a secondary table. Is there anyway around this? I don't particularly want to start messing with the DB schema since it is destined to break future upgrades.
jordan
 
Posts: 28
Joined: Fri Sep 23, 2011 7:55 am

Re: Canonical URLs and page titles / internal links

Postby adi_555 » Sun Nov 27, 2011 9:38 am

Hi ,

I am having a similar problem, there are duplicates reported by google on category meta description and title. but not for products.

Is there a way we can set this canonical thing ?
adi_555
 
Posts: 216
Joined: Mon Nov 08, 2010 10:21 am

Re: Canonical URLs and page titles / internal links

Postby jordan » Sun Nov 27, 2011 10:06 am

I modified Simon's script to support multiple categories. If multiple categories are found it uses the one with the lowest sort_order (i.e. to highest priority category in sort). Updated vqmod is attached. Let me know if you have any problems with it.

I am also thinking about doing the same thing if no breadcrumbs are found, but not sure when I'll get around to that.
Attachments
category_in_canonical_url.xml
(2.31 KiB) Downloaded 385 times
jordan
 
Posts: 28
Joined: Fri Sep 23, 2011 7:55 am

Re: Canonical URLs and page titles / internal links

Postby jordan » Sun Nov 27, 2011 10:10 am

adi_555 wrote:Hi ,

I am having a similar problem, there are duplicates reported by google on category meta description and title. but not for products.

Is there a way we can set this canonical thing ?

I am seeing the same thing as adi_555 -- doesn't seem to use canonical url for categories. Is this a bug? Categories can have multiple urls with SEO mod.
jordan
 
Posts: 28
Joined: Fri Sep 23, 2011 7:55 am

Re: Canonical URLs and page titles / internal links

Postby wernerrenrew » Sun Nov 27, 2011 10:36 am

Hi,

I am working on a extention for my customers the canonical tag was one of the things that was modified, i choose to fall back to the latest added category so ppl will not have problems with duplicate sort orders or forgot to set it all together.

The categories are added to the database with an auto increment function on the category id.

Regards Werner
User avatar
wernerrenrew
 
Posts: 170
Joined: Thu Oct 27, 2011 1:48 pm
Location: Netherlands

Re: Canonical URLs and page titles / internal links

Postby adi_555 » Sun Nov 27, 2011 10:56 am

jordan wrote:
adi_555 wrote:Hi ,

I am having a similar problem, there are duplicates reported by google on category meta description and title. but not for products.

Is there a way we can set this canonical thing ?

I am seeing the same thing as adi_555 -- doesn't seem to use canonical url for categories. Is this a bug? Categories can have multiple urls with SEO mod.


I think daniel should respond on this as I can see alot of people have a similar issue.
adi_555
 
Posts: 216
Joined: Mon Nov 08, 2010 10:21 am

Re: Canonical URLs and page titles / internal links

Postby jordan » Mon Nov 28, 2011 10:12 pm

Daniel,

Can you address why category pages don't have a canonical url? There are multiple routes to a given category page leading to duplicate pages. Wondering if there is a specific reason for this, or if it was just an oversite one us can patch it and submit a fix.
jordan
 
Posts: 28
Joined: Fri Sep 23, 2011 7:55 am

Re: Canonical URLs and page titles / internal links

Postby adi_555 » Thu Dec 01, 2011 6:02 pm

BUMP!
adi_555
 
Posts: 216
Joined: Mon Nov 08, 2010 10:21 am

Re: Canonical URLs and page titles / internal links

Postby Chones » Thu Dec 01, 2011 10:20 pm

Could you explain how you are getting multiple routes to a given category?

Products in several categories I can understand, a sub-category in several categories doesn't seem to make sense.

Just create a new sub-category in the other categories to fix the problem. That's why there's no need for canonical URLs for categories.

Unless I'm missing something.

Or is it just that Google is indexing your ?sort=, ?page= for your categories, if this is the case you just need to block access with a robots.txt file.
User avatar
Chones
 
Posts: 755
Joined: Wed Mar 24, 2010 1:07 pm
Location: London

Re: Canonical URLs and page titles / internal links

Postby adi_555 » Fri Dec 02, 2011 8:42 am

Chones wrote:Could you explain how you are getting multiple routes to a given category?

Products in several categories I can understand, a sub-category in several categories doesn't seem to make sense.

Just create a new sub-category in the other categories to fix the problem. That's why there's no need for canonical URLs for categories.

Unless I'm missing something.

Or is it just that Google is indexing your ?sort=, ?page= for your categories, if this is the case you just need to block access with a robots.txt file.


For ex category is (lenovo)

/Lenovo/lenovo-s10
/Lenovo
/Lenovo?sort=pd.name&order=ASC
/Lenovo?sort=rating&order=ASC
/pc/Lenovo
adi_555
 
Posts: 216
Joined: Mon Nov 08, 2010 10:21 am

Re: Canonical URLs and page titles / internal links

Postby Chones » Fri Dec 02, 2011 6:10 pm

Okay, so it looks like you should only have the category indexed as:

/pc/Lenovo

I may be wrong but this looks like a product within that category:

/Lenovo/lenovo-s10

To get rid of the sort listings you need a robot.txt file in the root of your site - I recommend the robots.txt file includes the following for good SEO.

Code: Select all
User-agent: *
Disallow: /*?sort
Disallow: /*&sort
Disallow: /*?limit
Disallow: /*&limit
Disallow: /*?route=checkout
Disallow: /*?route=account
Disallow: /*?route=product/search
Disallow: /*&keyword
Disallow: /*?page=1
Allow: /

That leaves /Lenovo and /pc/Lenovo. There should be no way for a Google bot to get to /Lenovo without going via /pc so you may want to look at the links in your navigation that go to /Lenovo. Make sure they all include /pc/.

Hope that helps.
User avatar
Chones
 
Posts: 755
Joined: Wed Mar 24, 2010 1:07 pm
Location: London

Re: Canonical URLs and page titles / internal links

Postby adi_555 » Fri Dec 02, 2011 8:47 pm

Chones wrote:Okay, so it looks like you should only have the category indexed as:

/pc/Lenovo

I may be wrong but this looks like a product within that category:

/Lenovo/lenovo-s10

To get rid of the sort listings you need a robot.txt file in the root of your site - I recommend the robots.txt file includes the following for good SEO.

Code: Select all
User-agent: *
Disallow: /*?sort
Disallow: /*&sort
Disallow: /*?limit
Disallow: /*&limit
Disallow: /*?route=checkout
Disallow: /*?route=account
Disallow: /*?route=product/search
Disallow: /*&keyword
Disallow: /*?page=1
Allow: /

That leaves /Lenovo and /pc/Lenovo. There should be no way for a Google bot to get to /Lenovo without going via /pc so you may want to look at the links in your navigation that go to /Lenovo. Make sure they all include /pc/.

Hope that helps.


google can still get to lenovo if SEO url is enabled just buy www.xyz.com/lenovo , no matter what parent category it is in.

and seeing the above recommendation for robots file, you are also block search keywords, woudnt this affect the search listings????
adi_555
 
Posts: 216
Joined: Mon Nov 08, 2010 10:21 am

Re: Canonical URLs and page titles / internal links

Postby Chones » Sat Dec 03, 2011 11:05 am

Spiders crawl by following links, they don't guess URLs. You must have a link to http://www.xyz.com/lenovo on your site somewhere, that's why I said to check your navigation.

And the robots.txt file doesn't block any keywords, it stops search engines indexing URLs like this:

/index.php?route=product/search&keyword=blue

That way the search engines can focus on your products and not a lot of useless URLs.

See here for more details: http://www.robotstxt.org/robotstxt.html

Trust me, I know what I'm doing ;)
User avatar
Chones
 
Posts: 755
Joined: Wed Mar 24, 2010 1:07 pm
Location: London

Re: Canonical URLs and page titles / internal links

Postby alex1 » Sat Dec 03, 2011 5:34 pm

Good stuff guys.

I don't like the longer URLs, I do want to keep the canonical on the product pages to the short and clean URL.

What I was thinking was to add a query to pull the categories the product is in, and have it populate in the breadcrumb and category, but keep the URL the same.

Anyone know what query to add here?

Thanks
alex1
 
Posts: 315
Joined: Sat Oct 16, 2010 1:49 am

Re: Canonical URLs and page titles / internal links

Postby alex1 » Sat Dec 03, 2011 8:24 pm

trying to hack this, so it shows breadcrumbs and categories even with the canonical url for products with one category.

I get this error:

[03-Dec-2011 20:10:59] PHP Fatal error: Call to a member function getCategoryPath() on a non-object in /catalog/controller/product/product.php on line 42

Here is the hacked code:

Code: Select all
      if (isset($this->request->get['path'])) {
         $path = '';
            
         foreach (explode('_', $this->request->get['path']) as $path_id) {
            if (!$path) {
               $path = $path_id;
            } else {
               $path .= '_' . $path_id;
            }
            
            $category_info = $this->model_catalog_category->getCategory($path_id);
            
            if ($category_info) {
               $this->data['breadcrumbs'][] = array(
                  'text'      => $category_info['name'],
                  'href'      => $this->url->link('product/category', 'path=' . $path),
                  'separator' => $this->language->get('text_separator')
               );
            }
         }
      } else {
      
         $path = '';
            
         foreach (explode('_', $this->model_catalog_product->getCategoryPath($this->request->get['product_id'])) as $path_id) {
            if (!$path) {
               $path = $path_id;
            } else {
               $path .= '_' . $path_id;
            }
            
            $category_info = $this->model_catalog_category->getCategory($path_id);
            
            if ($category_info) {
               $this->data['breadcrumbs'][] = array(
                  'text'      => $category_info['name'],
                  'href'      => $this->url->link('product/category', 'path=' . $path),
                  'separator' => $this->language->get('text_separator')
               );
            }
         }
      
      }


Any ideas? tia
alex1
 
Posts: 315
Joined: Sat Oct 16, 2010 1:49 am

Re: Canonical URLs and page titles / internal links

Postby spitos » Thu Mar 08, 2012 5:11 pm

jordan wrote:
adi_555 wrote:Hi ,

I am having a similar problem, there are duplicates reported by google on category meta description and title. but not for products.

Is there a way we can set this canonical thing ?

I am seeing the same thing as adi_555 -- doesn't seem to use canonical url for categories. Is this a bug? Categories can have multiple urls with SEO mod.


Add this before </modification> to the xml files above for a canonical url on category pages:
Code: Select all
   <file name="catalog/controller/product/category.php">
          <operation>
            <search position="after"><![CDATA[
            $this->document->setKeywords($category_info['meta_keyword']);
            ]]></search>
            <add><![CDATA[
         $this->document->addLink($this->url->link('product/category', 'path=' . $this->request->get['path']), 'canonical');
            ]]></add>
        </operation>
   </file>
Image Get it here
Google Analytics Expert - E-Commerce Tracking including Product Options, Goal & Funnel Reporting, Event Tracking, Search Tracking, Multi-Store compatibility & EU Cookie Law compliance. Works with Shoppica too!

Free Mods:
Remove Wishlist | Remember text in search box
Other Extensions:
Remove product counts, Opencart speedup & Improve page load time | All Extensions
User avatar
spitos
 
Posts: 258
Joined: Mon May 23, 2011 10:19 am
Location: UK

Next

Return to General Support

Who is online

Users browsing this forum: Alexa [Bot], cbserver, Google Feedfetcher, lloydmedley, PaulCutcliffe, soj47, XXX76 and 86 guests

Hosted by Arvixe Web Hosting