1

I would like to add more rewrites for a specific product.

For example I have Product a - url: urlpath/product-original-path.html

I would like three rewerites

  1. urlpath/product-old-path1.html
  2. urlpath/product-old-path2.html
  3. urlpath/product-old-path3.html

to http://website.com/product-original-path.html

I guess it isn't possible using core_url_rewrite. Any solutions? Extensions to solve that problem?

2

In you backend got to Catalog > URL Rewrite management and add a new rule. Now for the following steps

  1. Choose product
  2. Pick your product
  3. Either pick a category or skip
  4. Next in the form choose the store it applies to
  5. Fill out the request path which should be the URL you want to redirect

And that should be it

  • When I add first rewrite it works but I want to add another and then I get "ID Path for Specified Store already exists." – Ryan Nov 13 '14 at 9:21
0

Short Answer

Instead of creating a Product URL Rewrite, create a Custom URL Rewrite:

create custom rewrite

Repeat for the second and third paths, choosing a different value for ID Path each time.

Longer Explanation

Magento sets a unique constraint in the core_url_rewrite table for the combination of store_id and id_path. It relies on this to look up the correct URL for a particular entity, such as a product or category.

Here is an extract from Magento's core which loads the URL based on the store_id and id_path:

// app/code/core/Mage/Catalog/Model/Product/Url.php
protected function _getRequestPath($product, $categoryId)
{   
    $idPath = sprintf('product/%d', $product->getEntityId());
    if ($categoryId) {
        $idPath = sprintf('%s/%d', $idPath, $categoryId);
    }   
    $rewrite = $this->getUrlRewrite();
    $rewrite->setStoreId($product->getStoreId())
        ->loadByIdPath($idPath);
    if ($rewrite->getId()) {
        return $rewrite->getRequestPath();
    }   

    return false;
}

When you create a new URL Rewrite Rule for a product, the id_path is automatically set to product/<product_id>. However, Magento has a way of working around this limitation when it creates multiple redirects for the same product. See this method from the core:

// app/code/core/Mage/Catalog/Model/Url.php
protected function _saveRewriteHistory($rewriteData, $rewrite)
{   
    if ($rewrite instanceof Varien_Object && $rewrite->getId()) {
        $rewriteData['target_path'] = $rewriteData['request_path'];
        $rewriteData['request_path'] = $rewrite->getRequestPath();
        $rewriteData['id_path'] = $this->generateUniqueIdPath();
        $rewriteData['is_system'] = 0;
        $rewriteData['options'] = 'RP'; // Redirect = Permanent
        $this->getResource()->saveRewriteHistory($rewriteData);
    }

    return $this;
}   

The generateUniqueIdPath method simply generates a value based on the current time:

public function generateUniqueIdPath()
{   
    return str_replace('0.', '', str_replace(' ', '_', microtime()));
}   

So if you want to create URL Rewrites with id_path values that follow this logic, simply run this method in a stand-alone script. It will give you values that look like this: 68704200_1501155122.

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.