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 2 of 3
How to remove parent category path from sub category url? 
 
kvolta
Jr. Member
 
Total Posts:  7
Joined:  2009-12-31
 

I want to know how to do this in 1.5 also.

 
Magento Community Magento Community
Magento Community
Magento Community
 
kvolta
Jr. Member
 
Total Posts:  7
Joined:  2009-12-31
 

//if (null === $parentPath) {
//$parentPath = $this->getResource()->getCategoryParentPath($category);
//}
//elseif ($parentPath == ‘/’) {
$parentPath = ‘’;
//}
works in 1.5, please be sure to disable compliation if you are in production environment.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Trenza
Member
 
Avatar
Total Posts:  57
Joined:  2010-03-11
Dhaka, Bangladesh
 

I don’t like to hack any file. Is there any way in the magento admin panel to set any configuration for this purpose?

 
Magento Community Magento Community
Magento Community
Magento Community
 
roshanbhgt
Jr. Member
 
Total Posts:  3
Joined:  2011-06-17
 

In Magento 1.5 you will find this code in file called url.php at line no 805.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sinepo
Jr. Member
 
Total Posts:  1
Joined:  2011-10-21
 

//if (null === $parentPath) {
//$parentPath = $this->getResource()->getCategoryParentPath($category);
//}
//elseif ($parentPath == ‘/’) {
$parentPath = ‘’;
//}

The above css can run well with megento 1.4, thank you very much.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nasha
Sr. Member
 
Avatar
Total Posts:  138
Joined:  2009-04-15
 

Admin-panel > system > configuration > catalog > catalog > Use Categories Path for Product URLs= NO

 
Magento Community Magento Community
Magento Community
Magento Community
 
Styopchik
Jr. Member
 
Avatar
Total Posts:  13
Joined:  2010-08-20
 

nasha, thanks a lot!!!!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
Loaded Expert
Jr. Member
 
Total Posts:  25
Joined:  2008-05-10
Karachi
 
nasha - 21 October 2011 12:14 PM

Admin-panel > system > configuration > catalog > catalog > Use Categories Path for Product URLs= NO

Hi, this option is only valid for removing category path from product pages. For category pages full path is still included. can you suggest some alternate? editing code is not an option smile thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
kab8609
Moderator
 
Avatar
Total Posts:  821
Joined:  2009-04-07
Cleveland
 

For people saying

I don’t like to hack any file. Is there any way in the magento admin panel to set any configuration for this purpose?

or

editing code is not an option

, i’m sorry but there isn\’t a magical button in Magento that does this currently. You do need to overwrite some core code. However don\’t edit it the wrong way, edit it the right way!!!

You need to create a overwrite of this file: app/code/core/Mage/Catalog/Model/Url.php

starting a line 717 (on CE1.7.0.0) find this:

if (null === $parentPath{
            $parentPath 
$this->getResource()->getCategoryParentPath($category);
        
}
       
elseif ($parentPath == \'/\'{
            $parentPath 
\'\';
       
}

and change it to this:

//        if (null === $parentPath) {
//            $parentPath = $this->getResource()->getCategoryParentPath($category);
//        }
//        elseif ($parentPath == \'/\') {
            $parentPath \'\';
//        }

Then reindex (see screenshots)!!!

I\’m not going to go into details on how to overwrite a core (there are many tutorials out there how to correctly overwrite a core file) file but…

BAD: Editing app/code/core/Mage/Catalog/Model/Url.php <- You will be slapped
OKAY: Creating a file called app/code/local/Mage/Catalog/Model/Url.php
BEST: creating an extension that overwrites just the \"public function getCategoryRequestPath($category, $parentPath)\” of that file.

Image Attachments
Screen shot 2012-06-11 at 11.46.48 AM.pngScreen shot 2012-06-11 at 11.48.52 AM.png
 
Magento Community Magento Community
Magento Community
Magento Community
 
Loaded Expert
Jr. Member
 
Total Posts:  25
Joined:  2008-05-10
Karachi
 

hi kab8609, thanks for the best solution yet provided, i think your solution is the best one and update proof.

I would further like to know if is possible to override only the function “getCategoryRequestPath” instead of copying the the full file /app/code/core/Mage/Catalog/Model/Url.php

 
Magento Community Magento Community
Magento Community
Magento Community
 
kab8609
Moderator
 
Avatar
Total Posts:  821
Joined:  2009-04-07
Cleveland
 
Loaded Expert - 12 June 2012 07:54 AM

hi kab8609, thanks for the best solution yet provided, i think your solution is the best one and update proof.

I would further like to know if is possible to override only the function “getCategoryRequestPath” instead of copying the the full file /app/code/core/Mage/Catalog/Model/Url.php

Yes that would be the ideal choice in how to do this, however you will need to know how to make extensions. I may make an extension in the future for this, but unfortunately I can’t explain a step by step process in how to do it as it will take me 1-2 hours. I would suggest googling to find out how to make a magento extension (there are a few good resources out there) and trying it yourself.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Loaded Expert
Jr. Member
 
Total Posts:  25
Joined:  2008-05-10
Karachi
 

thanks kab8609. Can you convince magento team to add this feature in upcoming versions? this will be even better than having an extension smile.

 
Magento Community Magento Community
Magento Community
Magento Community
 
kat1
Jr. Member
 
Total Posts:  10
Joined:  2008-08-14
 

This works really nicely but leaves the urls in the Magento generated sitemap.xml file untouched.
Does anyone have any idea how that might be overridden also?
I took a look inside app/code/core/Mage/sitemap/Model/Sitemap.php wich seem to get it’s path from $_filePath but then I’m lost.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jasonr686
Jr. Member
 
Total Posts:  9
Joined:  2012-01-09
 

Does anyone have a solution for this, including the sitemap URLs? This is every important to me!

Thank you

 
Magento Community Magento Community
Magento Community
Magento Community
 
Jesper Hvejsel
Jr. Member
 
Total Posts:  2
Joined:  2009-01-25
 

I have a running site with a good SEO already.

But i would like to change the urls according to the suggestions here. If i make the changes and upload the files, will the old url’s then be 301 redirect to the new ones?

Say i have a customer linking to an old URL, will the old url be redirected?

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