Canonical URLs and page titles / internal links
43 posts
• Page 1 of 3 • 1, 2, 3
Canonical URLs and page titles / internal links
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.
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
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.
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.
-

wernerrenrew - Posts: 170
- Joined: Thu Oct 27, 2011 1:48 pm
- Location: Netherlands
Re: Canonical URLs and page titles / internal links
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
change to
edit: catalog/model/catalog/product.php
find
add before
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:
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:
Happy Coding!
Simon
------
Commercial Mods:
Google Merchant / Base XML Feed + Bing Shopping + Sitemaps - Automatic Friendly SEO URLs
Full List of UKSB Extensions and Mods
vQmod Generator - Develop & Test OpenCart on your Local Windows machine
Click here if I have helped you and you would like to make a donation
Simon
------
Commercial Mods:
Google Merchant / Base XML Feed + Bing Shopping + Sitemaps - Automatic Friendly SEO URLs
Full List of UKSB Extensions and Mods
vQmod Generator - Develop & Test OpenCart on your Local Windows machine
Click here if I have helped you and you would like to make a donation
-

uksitebuilder - Posts: 5602
- Joined: Thu Jun 09, 2011 3:37 pm
- Location: United Kindgom
[Solved]: Canonical URLs and page titles / internal links
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
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.
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
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 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
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.
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
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
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
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
-

wernerrenrew - Posts: 170
- Joined: Thu Oct 27, 2011 1:48 pm
- Location: Netherlands
Re: Canonical URLs and page titles / internal links
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
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.
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
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.
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.
http://scarletandjones.com/
http://sharpdressedman.co.uk/
http://coffincompany.co.uk/
http://horsesculptures.co.uk/
If I've helped you out, why not buy me a beer? http://craigmurray.me.uk
http://sharpdressedman.co.uk/
http://coffincompany.co.uk/
http://horsesculptures.co.uk/
If I've helped you out, why not buy me a beer? http://craigmurray.me.uk
-

Chones - Posts: 755
- Joined: Wed Mar 24, 2010 1:07 pm
- Location: London
Re: Canonical URLs and page titles / internal links
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
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.
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.
/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.
http://scarletandjones.com/
http://sharpdressedman.co.uk/
http://coffincompany.co.uk/
http://horsesculptures.co.uk/
If I've helped you out, why not buy me a beer? http://craigmurray.me.uk
http://sharpdressedman.co.uk/
http://coffincompany.co.uk/
http://horsesculptures.co.uk/
If I've helped you out, why not buy me a beer? http://craigmurray.me.uk
-

Chones - Posts: 755
- Joined: Wed Mar 24, 2010 1:07 pm
- Location: London
Re: Canonical URLs and page titles / internal links
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
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
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

http://scarletandjones.com/
http://sharpdressedman.co.uk/
http://coffincompany.co.uk/
http://horsesculptures.co.uk/
If I've helped you out, why not buy me a beer? http://craigmurray.me.uk
http://sharpdressedman.co.uk/
http://coffincompany.co.uk/
http://horsesculptures.co.uk/
If I've helped you out, why not buy me a beer? http://craigmurray.me.uk
-

Chones - Posts: 755
- Joined: Wed Mar 24, 2010 1:07 pm
- Location: London
Re: Canonical URLs and page titles / internal links
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
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
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:
Any ideas? tia
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
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>
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
-

spitos - Posts: 258
- Joined: Mon May 23, 2011 10:19 am
- Location: UK
43 posts
• Page 1 of 3 • 1, 2, 3
Who is online
Users browsing this forum: Alexa [Bot], cbserver, Google Feedfetcher, lloydmedley, PaulCutcliffe, soj47, XXX76 and 86 guests













