Page 1 of 2

[HOW TO] Remove category names from product URLs

Posted: Fri Aug 26, 2011 10:42 pm
by Johnathan
IN:

Code: Select all

1.4.x: /catalog/model/tool/seo_url.php
1.5.x: /catalog/controller/common/seo_url.php
REPLACE THE FIRST INSTANCE OF:

Code: Select all

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

Code: Select all

$url = '/' . $query->row['keyword']; 
If you want sub-categories to not show their parent categories in the URL, then replace both instances of that line with the replacement.

More tutorials are available at OpenCartX.com/tutorials

Re: [HOW TO] Remove category names from product URLs

Posted: Sat Aug 27, 2011 5:00 am
by uksitebuilder
Only issue I found is that it kills the breadcrumbs to a degree

Re: [HOW TO] Remove category names from product URLs

Posted: Sat Aug 27, 2011 7:57 am
by Johnathan
Yes, that's a downside. You could get around it by including the breadcrumbs in a cookie or some other session data, but I don't know how easy (or convenient) that would be to do. If anyone has a better suggestion, I'm all ears.

Re: [HOW TO] Remove category names from product URLs

Posted: Mon Sep 19, 2011 2:45 pm
by Gloyns
Johnathan, this is awesome :) Thank you so much. I'd much rather just add the manufacturer to the product name anyway and have a nice clean URL which isn't duplicated throughout the site, E.g. delboyselectronics.co.uk/sony-bravia-42gz8gfh/ rather than delboyselectronics.co.uk/sony/bravia-42gz8gfh, that way you can your branded keywords into the URL and provide a good user experience.

Re: [HOW TO] Remove category names from product URLs

Posted: Fri Mar 02, 2012 10:43 am
by DragonJ
I'm using this mod and it's working good. I was wondering if anyone has come up with a solution to the now-missing/incomplete breadcrumbs.

Re: [HOW TO] Remove category names from product URLs

Posted: Sat Mar 03, 2012 2:11 am
by DragonJ
FOLLOW UP: A developer made a vQmod for me today (Breadcrumbs Everywhere) and it works spot on for adding a breadcrumb. Of course if your product is in multiple categories, it's limited to showing only the first category, but that was expected. It still does the job I need it to.

http://www.opencart.com/index.php?route ... on_id=5241

Re: [HOW TO] Remove category names from product URLs

Posted: Wed Mar 21, 2012 11:09 pm
by expanism
Johnathan wrote:IN:

Code: Select all

1.4.x: /catalog/model/tool/seo_url.php
1.5.x: /catalog/controller/common/seo_url.php
REPLACE THE FIRST INSTANCE OF:

Code: Select all

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

Code: Select all

$url = '/' . $query->row['keyword']; 
If you want sub-categories to not show their parent categories in the URL, then replace both instances of that line with the replacement.
Wow that simple, so working this way we can remove canonical url from product page, what do you think?

Re: [HOW TO] Remove category names from product URLs

Posted: Thu Mar 22, 2012 6:24 am
by Johnathan
Unless the canonical URL is causing you problems, I would just leave it in.

Re: [HOW TO] Remove category names from product URLs

Posted: Tue Apr 17, 2012 5:56 pm
by dunks
this is SUPER AWESOME !! :banana:

What effect on google crawl??

Re: [HOW TO] Remove category names from product URLs

Posted: Sun Oct 07, 2012 8:59 am
by CrysTim
Johnathan wrote:IN:

Code: Select all

1.4.x: /catalog/model/tool/seo_url.php
1.5.x: /catalog/controller/common/seo_url.php
REPLACE THE FIRST INSTANCE OF:

Code: Select all

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

Code: Select all

$url = '/' . $query->row['keyword'];
If you want sub-categories to not show their parent categories in the URL, then replace both instances of that line with the replacement.
Not working for me :(
I have:
- Opencart 1.5.4
- www.shop.com/category/subcategory link working
- www.shop.com/product link working
- no vqmods or seo module installed....

Can somebody help me? On wich version that code worked?

Re: [HOW TO] Remove category names from product URLs

Posted: Sat Oct 13, 2012 12:18 pm
by vtdoan
CrysTim wrote:
Johnathan wrote:IN:

Code: Select all

1.4.x: /catalog/model/tool/seo_url.php
1.5.x: /catalog/controller/common/seo_url.php
REPLACE THE FIRST INSTANCE OF:

Code: Select all

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

Code: Select all

$url = '/' . $query->row['keyword'];
If you want sub-categories to not show their parent categories in the URL, then replace both instances of that line with the replacement.
Not working for me :(
I have:
- Opencart 1.5.4
- http://www.shop.com/category/subcategory link working
- http://www.shop.com/product link working
- no vqmods or seo module installed....

Can somebody help me? On wich version that code worked?
Try this:
IN:

Code: Select all

catalog\controller\product\category.php
Replace:

Code: Select all

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

Code: Select all

'href'        => $this->url->link('product/product',  'product_id=' . $result['product_id']) 
hope this helps you :)

Re: [HOW TO] Remove category names from product URLs

Posted: Mon Jun 24, 2013 6:44 am
by cwswebdesign
I've done this to remove all category names from the actual product page link and it works on the site but I'm seeing the following in the error log:

2013-06-23 10:45:24 - PHP Warning: explode() expects parameter 2 to be string, array given in /home/----------/public_html/----------/vqmod/vqcache/vq2-catalog_controller_common_seo_url.php on line 129
2013-06-23 10:45:24 - PHP Warning: Invalid argument supplied for foreach() in /home/----------/public_html/----------/vqmod/vqcache/vq2-catalog_controller_common_seo_url.php on line 131
2013-06-23 10:45:25 - PHP Warning: explode() expects parameter 2 to be string, array given in /home/----------/public_html/----------/vqmod/vqcache/vq2-catalog_controller_common_seo_url.php on line 129
2013-06-23 10:45:25 - PHP Warning: Invalid argument supplied for foreach() in /home/---------/public_html/----------/vqmod/vqcache/vq2-catalog_controller_common_seo_url.php on line 131
2013-06-23 11:32:26 - PHP Notice: Undefined index: query in /home/---------/public_html/----------/vqmod/vqcache/vq2-catalog_controller_common_seo_url.php on line 43
2013-06-23 11:32:26 - PHP Notice: Undefined offset: 1 in /home/---------/public_html/----------/vqmod/vqcache/vq2-catalog_controller_common_seo_url.php on line 49

Any thoughts? This is using v1.5.5.1

DL

Re: [HOW TO] Remove category names from product URLs

Posted: Tue Oct 15, 2013 4:50 am
by krisbolleter
Hey There!

So I have gotten this to work on my sub-category pages, however my question is, how can I now add the parent category directory back into the product page specific URL (ie:

Parent Category URL: ../parent-category
Sub-Category URL: ../sub-category
Product URL : ../parent-category/product-url

)

any help would be greatly appreciated! :)

Re: [HOW TO] Remove category names from product URLs

Posted: Fri Apr 11, 2014 2:03 am
by RedHighHeels
LOL all i had to do is remove a dot. wasted 3h on this .. no information about this problem at all. someone should write a xml for this and sell it im sure people will buy it :)

Re: [HOW TO] Remove category names from product URLs

Posted: Sun Nov 02, 2014 3:17 pm
by ncwsolution
excellent post and superb following with great answers, thanks Johnathan

Re: [HOW TO] Remove category names from product URLs

Posted: Tue Jan 27, 2015 4:17 pm
by mmjy
I was wondering if this solution help SEO and rankings, and avoid duplicate content from search engines?

Re: [HOW TO] Remove category names from product URLs

Posted: Tue Jan 27, 2015 11:02 pm
by Johnathan
Unlikely -- OpenCart includes canonical tags, so it shouldn't be indexing duplicate content for product pages.

Re: [HOW TO] Remove category names from product URLs

Posted: Wed Feb 04, 2015 6:23 pm
by nicoletaradu
Thank you so much it works!! for my opencart website
http://www.magneticmarket.ro

Re: [HOW TO] Remove category names from product URLs

Posted: Tue Sep 15, 2015 9:11 pm
by PBVLLP
Hello All,

We are finding a strange issue - when we delete duplicate product record [erroneously created in the first place] the url alias table is not automatically updated - this table retains the url alias for the product record already deleted.

is this a normal opencart known defect? is there any fix for this?

The issue is since duplicate seo key word is retained, it gives product not found error when customer tries to visit a product page from a cateogry>product listing page.

thanks for guidance.

Re: [HOW TO] Remove category names from product URLs

Posted: Thu Oct 01, 2015 5:05 pm
by kazihaha
Johnathan wrote:IN:

Code: Select all

1.4.x: /catalog/model/tool/seo_url.php
1.5.x: /catalog/controller/common/seo_url.php
REPLACE THE FIRST INSTANCE OF:

Code: Select all

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

Code: Select all

$url = '/' . $query->row['keyword'];
If you want sub-categories to not show their parent categories in the URL, then replace both instances of that line with the replacement.

More tutorials are available at OpenCartX.com/tutorials
not work for my opencart 2.0.3.1, I still see
localhost/journal/may-photocopy/canon/canon-ir-2002n.html -> when I access "may-photocopy", then "canon", then "canon-ir-2002"
http://localhost/journal/canon-ir-2002n.html -> when I access this "canon-ir-2002n" from the home page.

Please help me.