Magento URL Rewrites for attribute + category combos

Magento makes it easy to create URL rewrites based on categories, it also makes it easy to make rewrites based on products, but what about attributes?

It’s fairly easy to create a URL rewrite based on attributes, so in this short guide we’ll show you how to create attribute + category combo URL rewrites.

To create a URL rewrite based on an attribute and a category in Magento, you’re going to need three things:

  1. The category ID
  2. The attribute code Note: This must be an attribute available for layered navigation for this method to work!
  3. The attribute value ID

The category ID can be found very simply on the category page in the backend:

Where to find the category ID
Where to find the category ID

The attribute name is simple – it’s the attribute code set in the Magento backend:

Where to find the Attribute Code
Where to find the Attribute Code

Lastly, the attribute value ID. This is a bit trickier, as it doesn’t appear in many places on the front or back-end of the site. Probably the easiest place to find it is by going to a layered navigation page for that attribute value, and it will be in the URL:

Where to find the Attribute ID
Where to find the Attribute ID

It can also be found in two other ways easily, by right clicking on the dropdown/multiselect in the create product page in the backend and looking at the ‘value’ of that select value, or by looking at the value in the database.

Once you’ve got those three things, try going to the following URL:

[base-url]/catalog/category/view/id/[category-id]?[attribute-code]=[attribute-value-id]

That should take you to the desired page, filtering that category for that attribute value. If this is all correct, then go to Catalog > URL Rewrite Management and create a new Custom URL Rewrite.

Example URL rewrite
Example URL rewrite

This example will create a 301 redirect for black CD players at the URL [store-url]/black-cd-players.

Note that you have to use 301 or 302 redirects for these URL rewrites, unfortunately, as layered navigation will not work further under that URL.

3 Replies to “Magento URL Rewrites for attribute + category combos”

  1. sorry sir, that way is complete bullshit. make a category with the name and add the products, thats how its supposed to be.

    1. Sorry, but it’s really not.

      Let’s say you have an attribute, colour, and a category, chairs, and you want a URL for blue chairs – you wouldn’t create a category for blue chairs, that would be ridiculous.

      Especially considering the amount of combinations you could have, manufacturer, size, material, colour, etc. Those should remain in attributes.

      Also, if you then wanted to add an attribute value later down the line, you would have to create a new category for every one of your site categories. It’s ridiculous.

  2. Thanks for the article, really gave me direction.
    I did not need to do a 301 or 302 redirect, as my other attribute filters still worked after this.

    Thx for the input!

    I had something like “consumer-light-truck” map to “catalog/category/view/id/41/?commercial_categorization=1320&customer_segment=250” and then I was able to use the other attribute to filter even more.

    Cool stuff!

Leave a Reply to adminCancel reply