How to make Opencart more SEO friendly with constant URLs

If you use Opencart you will notice the URL of the end product page page varies depending on which route is used to get to the product page.

If you go via a category the category breadcrumb is added to the URL resulting in domain/category/name-of-product

The Canonical tag helps overcome this problem but if you would prefer one constant URL you can fix it by editing some Opencart core files.

Two ways of making Opencart URL’s more constant

Important: BACK UP FIRST AND USE AT YOUR OWN RISK

1. Quick and easy but effects other breadcrumbs

2. Gives more control but more files to edit

1. Go to

catalog > Controller > product

open category.php and find (approx line 393)

'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'])

Replace it with

'href' => $this->url->link('product/product', $url . '&product_id=' . $result['product_id'])

save as category.php and upload.

See if that worked in the category section and if it did
do the same to manufacturer.php

The code is slightly different in manufacturer.php
find (approx line4 67)

'href' => $this->url->link('product/product', $url . '&manufacturer_id=' . $result['manufacturer_id'] . '&product_id=' . $result['product_id'])

and replace with,

'href' => $this->url->link('product/product', $url . '&product_id=' . $result['product_id'])

—————————————–

2. If you don't want to change the breadcrumbs but only the links from
the manufacturer and category sections.

rather than replacing

'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'])

just add another line

'hrefv1seo' => $this->url->link('product/product', $url . '&product_id=' . $result['product_id'])

(remember to add a comma at end of previous line)

Add this extra line to both manufacturer.php and category.php

You will then have to edit category.tpl and manufacturer_info.tpl in

catalog > view > theme > yourtheme > template > product

find the bits you want to change, (image and link in the main
grid of products( and replace

php echo $product['href'];

with

php echo $product['hrefv1seo'];

NOTE: NEITHER ARE FULLY TESTED USE AT YOUR OWN RISK

The second way of doing this is by far the best, but it will require editing files in your theme also.

Any comments welcome and appreciated.

This entry was posted in Web Work.