Magento – probably the most comprehensive and sophisticated e-commerce systems available to those who can afford it, that is a complete pain in the neck to develop for. I’ve developed a love hate relationship with Magento that I’m still not sure if it’s that I love to hate it.
A recent problem arose during an e-commerce website development where I had categories with only one product in each, so when the customer clicks on the category they are displayed a grid view of the product in the category, this is perfect when there are many products to display, but these categories only had one, so the customer was having to click twice before getting to the actual product, for me and anyone else this is one click too many. I wanted the customer to click on the category and be displayed the product directly, bypassing the grid view – seems simple!
As far as I can tell there’s two ways of doing this.
1) By developing a bit of code to setup filtering if categories only have one product to display it otherwise display the grid view of all the products. There is an extension for this which I wasn’t able to get installed or working but that could be because I’m using the professional version.
2) By using 301 redirects, Magento has options to directly enter redirections without having to edit the .htaccess file.
I ended up going with option two and here’s how to do it…
- All of the redirecting is done through the menu option Catalog –> URL Rewrite Management.
- Keep in mind that Magento creates system redirects for categories and products which convert category id’s and product id’s into their respective seo friendly urls.
- It’s a good idea to take a note of the category ID number from the current list of redirects, either by doing a search in the request path or the target path. The category ID is used when creating the new redirect.
- Another important tip is to have two tabs of URL rewrite management as it is very likely you will need to edit a rule before being able to save your new rule (see below).
- To create a redirect from a category page directly to a product page click on Add URL Rewrite.
- From the drop-down click and select CUSTOM
- In the ID Path put the category ID you found earlier in the same format category/xxx for example category/71
- In the request path put the path of the category you want redirected. Remember to put all the path after your domain name for example if your category URL is www.mytestshop.com/flowers/roses.html the request path for this would be flowers/roses.html
- In the target part put the path of the product you want to be redirected to. Remember again to put the full path that is after your domain name.
- Change the Redirect drop-down to Permanent (301) – Important otherwise the redirect will not work.
- Click on save
- It is more than likely that at this stage you will get an error stating “Request Path for Specified Store already exists” This will be because Magento creates system redirects as mentioned in step one. In another tab open your admin area of your Magento store, navigate to Catalog –> URL Rewrite Management and search for the system redirect for the category using the Request Path search field, once found edit the redirect and click on delete.
- Return to your unsaved redirect tab and click on save, you should now get the green tick and confirmation that the redirect was saved.
- Go to your store and test your redirect, there should be no requirement to flush the cache or reindex as the information is written directly to the .htaccess file.
The error message you will most probably receive when trying to save the new 301 redirect