1

I want to put a Magento Redirect rule to change the URL for filtering products and category.

When I use the filter in a category, the urls are look like this :

FROM: http://example.com/redwine

TO : http://example.com/redwine//cat/france

So, basically I want to remove the //cat. How can I do this trough either .htaccess or a hack in magento?

1 Answer 1

1

You cannot remove it entirely because the layered navigation filters need a request variable to determine what to filter. But you can change "cat" to something else.

It is defined in Mage_Catalog_Model_Layer_Filter_Category:

public function __construct()
{
    parent::__construct();
    $this->_requestVar = 'cat';
}

There is a setter setRequestVar() but unfortunately there is no way to call it between the filter being instantiated and being applied, without rewriting either the filter model or the filter block.

I would prefer to rewrite the block because the URL parameter is related to the user interface:

class Your_Module_Block_Catalog_Layer_Filter_Category 
    extends Mage_Catalog_Block_Layer_Filter_Category
{
    protected function _prepareFilter()
    {
        $this->_filter->setRequestVar('dog');
        return parent::_prepareFilter();
    }
}

Since you are asking for a HACK, you could change one of the classes directly instead, but I won't recommend hacking the core. And no, copying the file to app/code/local is not better.

Now the URLs are like this: http://example.com/redwine/dog/france. That is, the links in the filter navigation ar built this way, you could not accomplish this with .htaccess rewrite rules.

1
  • Hi @fschmengler thanks for your input! The reason for me wanting to change the filer, is primarily to navigate directly to the sub-category, for examle if i have a sub-cat in redwine called france, i can input to the url example.com/redwine/france and i get to the sub-cat. I am trying to achieve the same with the filter, because then i can output the category description etc. when a user uses filter. How can i achieve this? Because it won't help if I just change the cat to something else.
    – Patrick
    Commented Aug 24, 2015 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.