We're moving a site from MarketPress (WP plugin) to Magento.

  • Old WP site permalink structure is https://website.com/store/products/product-url

  • Magento url structure is https://www.website.com/category-name/product-url

How can we achieve this using htaccess, so that matching links are redirected correctly?



Assuming category-name varies, then I don't see any way you can do this solely from 301 rewrites in a .htaccess file. You may need to redirect the old URLs to a custom-coded script that will then redirect to the appropriate new URL, based on some sort of logic that will connect the old product URL to the appropriate new category-name/product-url

| improve this answer | |

As @Aric Watson states: you cannot do this with plain .htaccess, because the category-name-slug will not be predictable from .htaccess.

But... assuming you're only interested in creating 301's to the new URL's you don't actually need to know the new URL. A 301 to /catalog/product/view/id/[product id] would do as well, given that the canonical of your product detail page is set correct. So you won't lose any SEO value there.

In that scenario, you could write a script that writes those redirects according to a CSV that maps your old URL to the new product ID.

This function could look something like this:

 * Import rule for Magento Community
 * @param $fromUrl
 * @param $toUrl
public function createRuleCommunity($fromUrl, $toUrl)
    // Create rewrite:
    /** @var Mage_Core_Model_Url_Rewrite $rewrite */
    $rewrite = Mage::getModel('core/url_rewrite');

    // Check for existing rewrites:
    foreach($this->storeIds as $storeId)
        // Attempt loading it first, to prevent duplicates:



In this method, you could set $toUrl to /catalog/product/view/id/[product id]. But you could also set the new URL-key of the product, if you got that already. If you have the product ID, a simple $urlKey = Mage::getModel('catalog/product')->load($id)->getUrlKey() would do.

| improve this answer | |
  • Thanks for the detailed response. I'll surely give it a try on next project. The one I mentioned on this question, we happened to skip all the previous product specific SEO value & ended up only dealing with key categories. Cheers – tushonline Aug 16 '16 at 18:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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