开发者

Opencart, remove category string from the canonical URL of a product

In Magento there's a tick box - if you want or not to have the category in the product's link.

In Opencart there's no such think. What there is in Opencart - is a file which manages the SEO interpretation of links.

If you'll add "/" in front of the link within that file (the professionals who worked with it know about it) that will make the link absolute instead of relative and the product will appear at the beginning of the web site root.

My concern is that at some point this will break and I'm looking for a solution which can be applied on a commercial platform 20k+ products where failing can bring real damage.

The files I was talking about are these:

1.4.x: /catalog/model/tool/seo_url.php        
1.5.x: /catalog/controller/common/seo_url.php

The change I already know you need to do is:

$url .= '/' . $query->row['keyword']; 

replace with:

$url = '/' . $query->row['keyword']; 

It breaks things such as breadcrumbs, again - my concern is that I don't know what other things it breaks therefore I'm look开发者_如何学JAVAing for another solution.

SEO is mandatory, any SEO advice / plugin applied on Opencart will be more than welcomed. I'm constantly researching the market for related software, I'm willing to change the CMS (which will involve investing hours of development) if I can get better solutions.

Currently I'm dealing with Magento which is NOT flexible, each change drives us crezy - we're looking for something nu that buggy and difficult to work on.


What version of OpenCart are you working with? The latest?

The standard MVC structure of OpenCart combined with native PHP coding makes it a tremendously flexible CMS solution.. (I actually use the core for numerous types of sites).

OpenCart currently depends on the two files you mentioned combined with the SEO table in the database to handle rewrites.

It does not really 'break' the breadcrumbs. Breadcrums are more a history/navigation aid. With SEO urls if you enter a specific product URL you are navigating immediatly navigating to a specific item. So in the heirarchy it would only be one level below the home page..
e.g. yoursite.com/seoproduct

'home' -> 'seo product'

If you use the navigation heirarchy it still renders correctly (without the mod you mentioned) 'home' -> 'category -> 'sub-category' -> 'seo product'

That said, in theory it is easy to acomplish whatever you want with SEO urls. A simple modification to the two files is enough.


In practice, it just depends on how you want to handle them...

How are you going to handle specifying the SEO url for the product? Based on product name? Product model? Or are you going to use the native SEO field in the product info?

If it is the latter, the cart will automatically handle the rewrite. Unfortunately, letting the cart handle it natively also carries the greatest risk of links breaking over time as changes are made.

If it is one of the former options, you will need to make some modifications to how the SEO rewrite is handled.


Once you determine how you are going to be handling the rewrite you can put it in action...

The easiest modification would be to use the native SEO but then add in a redundant search fallback. If no results are found on the in the common/seo controller, have it search for results. If one is found display the product - if more than one is found display the results..

On the other hand, you could completly modify both files and go with a custom SEO handling. (again using a search to find the product)...

I have done it both ways... The first tends to have a bit better performance as it does database/text search only if the direct query returns no results...


There is a canonical tag in the head (at least in version 1.5.0) and in my testing this stayed the same regardless of whether or not the page was access through http://example.com/category1/product-123 or http://example.com/product-123.

<link href="http://example.com/product-123" rel="canonical" />

I would recommend looking at How can I create custom SEO-friendly URLs in OpenCart? for your other pages (information, cart, checkout, etc).


I've took the decision to:

  • Not set a string on the SEO field of each category
    • This will not add the category name before the product

This means that instead of /category/product I'll have /product

As CarpeNoctumDC said, I could change the PHP files so that the category could've been removed automatically but the disadvantages I can see are:

  1. You need to update the core PHP files on each update
  2. Can't certify of there are places where that turns against you, since it's not part of the theme but it's part of the core of opencart

The good news is that there's no need for the brand / manufacturer string before the product name (as many of us probably need) because we can use the manufacturer feature for that.

In this way the category / subcategory can be non relevant SEO text (which in my case is), the product link is legitimately set by opencart to /{link} which is totally SEO friendly and if I need a representation of the link with the manufacturer I only have to set a SEO link to the manufacturer itself. This will generate /{manufacturer}/{link_of_the_product} which on top it has within the header a canonical link pointing towards /{link_of_the_product} - in this way Google will not be disappointed.

As this very moment I'm doing the exports / imports form the old Magento 1.6 which turned to be a pain to the opencart customized as mentioned above.

We've passed Google Panda - there's no bad history on the domain, no duplicate content so far (~10k products) - we'll see how things turn after this major update.

If Google doesn't agrees with this config, I will post warnings on this topic.

Bogdan

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜