Magento: rewrites pages with deeply nested categories

We are doing SEO optimization on our Magento storefront, and I need tips on the best way to change category URLs. Our SEO contractors want to change a bunch of URLs:

/base-cat/sub-cat1/sub-cat2.html 

to

 /seo-friendly-cat2.html. 

We have a bunch of nested categories (5 top levels and many subcategories up to 4 levels). Since this helps our customers deploy basic navigation, we are not sure if we want to change the hierarchy of categories. But we can make these url changes in 100 categories or so.

I know that we can do some of this using 301 rewrites (using the built-in rewriting module Magento.htaccess), but what is the best way to approach this? One drawback I see using 301s is that the main navigation will still have a long subcategory URL in it. Should I take a look at creating a custom module that allows us to specify the exact URL for the categories (rather than the URL token specific to the hierarchy)? What is your advice?

+3
source share
1 answer

Most likely, you will want to write a script to do this for you and save it in Magento URL Management instead of some long unmanaged list of redirects / redirects to .htaccess or such.

The most important issue that I think will be in any collisions where the same file name exists and how you want to handle these.

 Mage::getModel('core/url_rewrite') ->setIsSystem(0) ->setStoreId($storeId) ->setOptions('RP') ->setIdPath('index.php?cat=c' . $categoryId . '_' . $this->strip($data['name']) . '.html') ->setTargetPath($categoryModel->getUrlPath() . '.html') ->setRequestPath('index.php?cat=c' . $categoryId . '_' . $this->strip($data['name']) . '.html') ->save(); 

This is just an example of how to add rewrite in Magento Rewrite Manager.

+4
source

Source: https://habr.com/ru/post/1336597/


All Articles