Post by countzer0 » Fri Nov 11, 2011 7:36 pm

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 http://www.sitename.com/category/sub-ca ... -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 http://www.sitename.com/category/sub-ca ... -name.html? I am using 1.5.1.1.

A happy OpenCart developer from Brighton.


User avatar
New member

Posts

Joined
Sat Jun 18, 2011 11:09 pm
Location - Brighton, UK

Post by wernerrenrew » Fri Nov 11, 2011 9: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
Active Member

Posts

Joined
Thu Oct 27, 2011 9:48 pm
Location - Netherlands

Post by uksitebuilder » Sat Nov 12, 2011 12:47 am

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:

User avatar
Guru Member

Posts

Joined
Thu Jun 09, 2011 11:37 pm
Location - United Kindgom

Post by countzer0 » Sat Nov 12, 2011 8:26 am

Wow Simon, this is exactly what I needed, thank you so much. Problem solved!

A happy OpenCart developer from Brighton.


User avatar
New member

Posts

Joined
Sat Jun 18, 2011 11:09 pm
Location - Brighton, UK

Post by jordan » Sun Nov 27, 2011 5:04 pm

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.

The Veloz Group
Beverly Hills Chairs: The leaders in ergonomic seating
Custom Tobacco: Customized cigars for any occasion


New member

Posts

Joined
Fri Sep 23, 2011 3:55 pm

Post by adi_555 » Sun Nov 27, 2011 5:38 pm

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 ?

Active Member

Posts

Joined
Mon Nov 08, 2010 6:21 pm

Post by jordan » Sun Nov 27, 2011 6:06 pm

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


The Veloz Group
Beverly Hills Chairs: The leaders in ergonomic seating
Custom Tobacco: Customized cigars for any occasion


New member

Posts

Joined
Fri Sep 23, 2011 3:55 pm

Post by jordan » Sun Nov 27, 2011 6:10 pm

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.

The Veloz Group
Beverly Hills Chairs: The leaders in ergonomic seating
Custom Tobacco: Customized cigars for any occasion


New member

Posts

Joined
Fri Sep 23, 2011 3:55 pm

Post by wernerrenrew » Sun Nov 27, 2011 6:36 pm

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
Active Member

Posts

Joined
Thu Oct 27, 2011 9:48 pm
Location - Netherlands

Post by adi_555 » Sun Nov 27, 2011 6:56 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.
I think daniel should respond on this as I can see alot of people have a similar issue.

Active Member

Posts

Joined
Mon Nov 08, 2010 6:21 pm

Post by jordan » Tue Nov 29, 2011 6:12 am

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.

The Veloz Group
Beverly Hills Chairs: The leaders in ergonomic seating
Custom Tobacco: Customized cigars for any occasion


New member

Posts

Joined
Fri Sep 23, 2011 3:55 pm

Post by adi_555 » Fri Dec 02, 2011 2:02 am

BUMP!

Active Member

Posts

Joined
Mon Nov 08, 2010 6:21 pm

Post by Chones » Fri Dec 02, 2011 6:20 am

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.

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


User avatar
Active Member

Posts

Joined
Wed Mar 24, 2010 9:07 pm
Location - London

Post by adi_555 » Fri Dec 02, 2011 4:42 pm

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

Active Member

Posts

Joined
Mon Nov 08, 2010 6:21 pm

Post by Chones » Sat Dec 03, 2011 2:10 am

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.

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


User avatar
Active Member

Posts

Joined
Wed Mar 24, 2010 9:07 pm
Location - London

Post by adi_555 » Sat Dec 03, 2011 4:47 am

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????

Active Member

Posts

Joined
Mon Nov 08, 2010 6:21 pm

Post by Chones » Sat Dec 03, 2011 7:05 pm

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 ;)

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


User avatar
Active Member

Posts

Joined
Wed Mar 24, 2010 9:07 pm
Location - London

Post by alex1 » Sun Dec 04, 2011 1:34 am

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

Active Member

Posts

Joined
Sat Oct 16, 2010 9:49 am

Post by alex1 » Sun Dec 04, 2011 4:24 am

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

Active Member

Posts

Joined
Sat Oct 16, 2010 9:49 am

Post by spitos » Fri Mar 09, 2012 1:11 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.
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
Google Analytics Expert - Advanced e-commerce tracking, Product & options reporting, transaction/conversion reporting, Google Adwords conversion & profit reporting, goal & funnel reporting, event tracking, site search tracking, multi-store compatibility, EU Cookie Law compliance and works with any theme or checkout! Easy vqmod install. Get it here


User avatar
Active Member

Posts

Joined
Mon May 23, 2011 6:19 pm
Location - UK
Who is online

Users browsing this forum: No registered users and 218 guests