Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
982 views
in Technique[技术] by (71.8m points)

url rewriting - Magento: Rewrites for deeply nested category pages

We are doing some SEO optimizations on our Magento store front and I need some advice on the best way to change category urls. Our SEO contractors want to change a bunch of urls from:

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

to

/seo-friendly-cat2.html.

We have a bunch of nested categories (5 top-level and a bunch of sub categories up to 4 levels deep). Since this helps our customers drill down through the main navigation, we aren't sure if we want to change the category hierarchy. But we might be doing these url changes on 100 categories or so.

I know we can do part of this with using 301 rewrites (using .htaccess or Magento's built-in rewrite module), but what is the best way to approach this? One of the drawbacks I see to using 301s is that the main navigation will continue to have the long, sub category url in it's link. Should I look at doing a custom module that allows us to specify an exact url for categories (rather than a url token specific to the hierarchy)? What is your advice?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

More than likely you're going to want to write a script to do this for you and keep it within Magento's URL Management instead of some long un-manageable list of rewrites/redirects in .htaccess or such.

Your biggest issue I would think would be any collisions where the same filename exists and how you would want to handle such.

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's into Magento's URL Rewrite Manager.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...