Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Page 1 of 3
How to remove parent category path from sub category url? 
 
t87599875
Jr. Member
 
Total Posts:  3
Joined:  2008-08-24
 

How to remove parent category path from sub category url?
Instance: http://www.xxx.com/a/b/c
I just want the category c url is http://www.xxx.com/c
products url can be done in this case, but i don’t know how to do it in sub categories url.

Help!

PS: it can’t be solved by url rewrite magagement. because 1: cache refreshed, will no change again. and custom type rewrite is not the right way for seo too for copy page reason.

 
Magento Community Magento Community
Magento Community
Magento Community
 
K3Live
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2009-08-30
 

Edit /app/code/core/Mage/Catalog/Model/Url.php

Find line 632 and change:

//if (null === $parentPath) {
                    //$parentPath = $this->getResource()->getCategoryParentPath($category);
                //}
                //elseif ($parentPath == '/') {
                    $parentPath '';
                
//}
File Attachments
Url.php  (File Size: 24KB - Downloads: 584)
 
Magento Community Magento Community
Magento Community
Magento Community
 
wokka
Member
 
Total Posts:  45
Joined:  2008-06-06
 

Thanks ses707 - This works great.

Now I can fully control the category urls’s - This should be an option in the backend admin.

Cheers again,
John

 
Magento Community Magento Community
Magento Community
Magento Community
 
GavinYu
Jr. Member
 
Total Posts:  3
Joined:  2009-11-26
 

Dear ses707,

Thank for your idea.
I downloaded your url.php and replaced the existing one /app/code/core/Mage/Catalog/Model/Url.php and also refreshed the cache already.
However, my site still cant work to remove the parents categories.

need to disable “Use Web Server Rewrites” to set “NO” at admin panel or any more action need to do?

Regards,
Gavin

 
Magento Community Magento Community
Magento Community
Magento Community
 
rubaducky
Member
 
Total Posts:  39
Joined:  2009-10-02
 

I also cannot get it to work. It still shows all my parent categories in the url.

Any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
rubaducky
Member
 
Total Posts:  39
Joined:  2009-10-02
 

*Update

I was able to get it to work by refreshing the catalog rewrites in cache management.

hope this helps

 
Magento Community Magento Community
Magento Community
Magento Community
 
fsm13
Member
 
Total Posts:  43
Joined:  2010-07-27
 

Hi,

Does anyone know if this can now be controlled in the admin, or in a more stable way than modifying the core code?

IE I’d like to minimise core code changes as much as possible.

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Itosa
Member
 
Total Posts:  39
Joined:  2009-07-02
 

In magento 1.4.1.1 The line numbers are: 673-678

//if (null === $parentPath) {
                //    $parentPath = $this->getResource()->getCategoryParentPath($category);
                //}
                //elseif ($parentPath == '/') {
                    $parentPath '';
                
//}
 
Magento Community Magento Community
Magento Community
Magento Community
 
Itosa
Member
 
Total Posts:  39
Joined:  2009-07-02
 

Do not forget to re-index Catalog URL Rewrites in Index Management.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Yellow Satsuma
Member
 
Total Posts:  41
Joined:  2010-02-13
 

ive changed the code, ive cleaned my cache, ive re indexed everything yet the damn thing wont go away smile Any ideas?

forget that: i had compiliation turned on, all works now.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Anjan Barik
Jr. Member
 
Avatar
Total Posts:  18
Joined:  2010-03-19
Kolkata
 

Go to app/code/core/Mage/Catalog/Model/

Open Url.php and go to line no 632 and comment(//) the below line
//if (null === $parentPath) {
//$parentPath = $this->getResource()->getCategoryParentPath($category);
//}
//elseif ($parentPath == \’/\’) {
$parentPath = \’\’; //(\’Don\’t comment it\’)
//}

Now save and upload it.

Now login to admin panel of your site then go to System->Config->Index Management and click on select all then select Reindex Data from the Action Dropdown then click on submit.

For details visit http://xhtmlandcsshelp.blogspot.com/2010/10/magento-remove-parent-category-path.html

 
Magento Community Magento Community
Magento Community
Magento Community
 
Unevenrex
Jr. Member
 
Total Posts:  3
Joined:  2010-04-13
 

This worked great. Thanks!

I don’t think anyone has noticed though that front page links under new products or best selling products that are shown as “See all Laptops, See all Shirts” still show the full url with cat and subcat on the url. Anyway around this to prevent double content?

 
Magento Community Magento Community
Magento Community
Magento Community
 
parmedius
Jr. Member
 
Total Posts:  4
Joined:  2010-06-10
 

I was able to get this working, but I was wondering if there was a way to apply this to a specific subcategory and not globally.  Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
blundz
Jr. Member
 
Total Posts:  1
Joined:  2010-08-03
 
Anjan Barik - 07 November 2010 06:41 AM

Go to app/code/core/Mage/Catalog/Model/

Open Url.php and go to line no 632 and comment(//) the below line
//if (null === $parentPath) {
//$parentPath = $this->getResource()->getCategoryParentPath($category);
//}
//elseif ($parentPath == \’/\’) {
$parentPath = \’\’; //(\’Don\’t comment it\’)
//}

Now save and upload it.

Now login to admin panel of your site then go to System->Config->Index Management and click on select all then select Reindex Data from the Action Dropdown then click on submit.

For details visit http://xhtmlandcsshelp.blogspot.com/2010/10/magento-remove-parent-category-path.html

----

Hi, I did your solution and it worked fine, however, I need the subcats to be still included in the URL. How can I remove the main cat from the URLs? For example I have a URL /main_cat/subcat/another_subcat/page.html, how can I just remove the “main_cat” and return only the “/subcat/another_subcat/page.html” part?

I have magento 1.3.2.3 installed and running.

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
 
K3Live
Jr. Member
 
Avatar
Total Posts:  9
Joined:  2009-08-30
 
chrismillerj - 02 March 2011 02:16 PM

Are there any options for Magento 1.5? I really need this! The code in Url.php is all different around line 632 though. :(

The affected lines remain the same they are just moved further down to lines 797-803.

File Attachments
Url.php  (File Size: 32KB - Downloads: 117)
 
Magento Community Magento Community
Magento Community
Magento Community
 
owen1982_2004
Jr. Member
 
Total Posts:  1
Joined:  2011-01-18
 

Hi,

The same code in 1.5 is in the line no 797, I have done it, but I can’t refer to the URL of the categories.

How to do that in 1.5?

Thanks!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 3