How to change magento category url to short url(friendly for google)?

I use magento, at the backend configuration, there’s a option: remove category url for products, well, the product url was, this was perfect feature. but the category url was still has layer, how can I remove the parent url for category url? so when I try to change the categories layer, then it’s okay.

Thanks advance, sorry for my poor english.

2 thoughts on “How to change magento category url to short url(friendly for google)?”

  1. Edit the file /app/code/core/Mage/Catalog/Model/Url.php as to comment these lines (see below) Should be lines 673 to 679 for 1.4, if not search for the code in the file.
    Then refresh url rewrites in admin -> system -> Index management

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

  2. i search a bit but didn’t find anything helpful, so i end up with this solution

    1st i create a observer the run after the category is saved,


    then in my observer i add a custom url rewrite that make our category url directly accessible (

    public function setUrlRedirect($observer) {
        $e = $observer->getEvent();
        $c = $e->getCategory();
        // getting updated data, 
        $data = $observer->getDataObject()->getData();
        $c = Mage::getModel("catalog/category")->load($c->getId());
        $url = $c->getUrl();
        $handle = $data['url_key'];
        $p = 'catalog/category/view/id/' . $c->getId(); /*$handle . ".html";*/
        $id = 'seo-frindly/cat-' . $c->getId() .'.html';
        $urlMdoule =  Mage::getModel('core/url_rewrite');
        $storeId =  Mage::app()->getStore()->getStoreId();
        if (  $urlMdoule->loadByIdPath($id)->getId() ) {
            // update
            $o = $urlMdoule->loadByIdPath($id);
            ->setTargetPath( $p )// Put the actual path
            ->setRequestPath( $handle .'.html')
        } else {
           // new
            ->setTargetPath( $p )// Put the actual path
            ->setRequestPath( $handle .'.html')

    now when ever you save the category, it will be accessible from the shorter url,

    just add the rel=”canonical” attribute in head so google will index the shorter seo firendly links

Leave a Reply

Your email address will not be published. Required fields are marked *